n = int(input())
operations = [input().strip() for _ in range(2 * n)]
current = 1
adjust_count = 0
queue = []
for op in operations:
if op.startswith('head add'):
x = int(op.split()[-1])
queue.insert(0, x)
elif op.startswith('tail add'):
x = int(op.split()[-1])
queue.append(x)
elif op == 'remove':
if queue and queue[0] == current:
queue.pop(0)
current += 1
else:
adjust_count += 1
queue.sort()
while queue and queue[0] < current:
queue.pop(0)
if queue and queue[0] == current:
queue.pop(0)
current += 1
print(adjust_count)