Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.

Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.

That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.

Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.


-----Input-----

The first line of input contains the integer n (1 ≤ n ≤ 3·10^5) — the number of boxes.

Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. 

It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.


-----Output-----

Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.


-----Examples-----
Input
3
add 1
remove
add 2
add 3
remove
remove

Output
1

Input
7
add 3
add 2
add 1
remove
add 4
remove
remove
remove
add 6
add 7
add 5
remove
remove
remove

Output
2



-----Note-----

In the first sample, Daru should reorder the boxes after adding box 3 to the stack.

In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.

Difficulty: interview

Starter code:

Solutions:
import sys

def main():
    n = int(input())
    n = n*2
    u = 0
    res = 0
    x = []
    for i in range(n):
        s = sys.stdin.readline()
        if s[0] == 'r':
            u+=1
            if len(x)==0:
                continue
            if x[-1] == u:
                x.pop()
            else:
                x = []
                res +=1
        else:
            a,b = s.split()
            x.append(int(b))
    print(res)


main()

from collections import deque
n=int(input())
s=0
c=1
q=deque([])
l=False
for i in range(2*n):
    t=input()
    if t[0]=='a':
        m=int(t[4:])
        q.append(m)
        l=False
    else:
        if len(q)>0:
            f=q.pop()
            if l==False and f!=c:
                s+=1
                l=True
                q=[]
        c+=1
print(s)

stack = []
next_pop_num = 1
r = 0


for _ in range(2 * int(input())):
    command = input()
    if command.startswith('add'):
        n = int(command[4:])
        stack.append(n)
    else:
        if stack and stack[-1] != next_pop_num:
            r += 1
            stack = []
        if stack:
            stack.pop(-1)
        next_pop_num += 1

print(r)


from sys import stdin, stdout

n = int(stdin.readline())
used = [0 for i in range(n + 1)]
delete = set()
stack = []
ans = 0
cnt = set()
number = 1
label = 0

for i in range(2 * n):
    s = stdin.readline().strip().split()
    
    while stack and stack[-1] in delete:
        cnt.discard(stack[-1])
        stack.pop()
        
    
    if s[0] == 'add':
        stack.append(int(s[1]))
        
        if label:
            cnt.add(int(s[1]))
            
    else:
        if label and not len(cnt):
            delete.add(number)
        elif stack[-1] == number:
            cnt.discard(stack[-1])
            stack.pop()
        else:
            ans += 1
            cnt = set()
            delete.add(number)
            label = 1
            
        
        number += 1

stdout.write(str(ans))

n=int(input())
mas=[]
p=0
r=0
for i in range(2*n):
    s=input().split()
    if s[0]=='add':
       mas.append(int(s[1]))
    else:
        r += 1
        if len(mas)>0 and r==mas[-1]:
            del mas[-1]
        elif len(mas)>0:
            p+=1
            mas=[]
print(p)

from collections import deque
import sys

n = int(input())

q = deque([])
toBe = 1
ans = 0

flag = 0

inp = [0] * (n * 2)

for i in range(2 * n):
    inp[i] = sys.stdin.readline().strip()

for i in range(2 * n):
    s = inp[i].split()
    if len(s) == 2:
        k = int(s[1])
        q.append(k)
        if len(q) == 1:
            continue
        if k != q[-2] - 1:flag = 0
    else:
        #print(toBe, flag, ans)
        if q and toBe != q[-1]:
            #print(q, toBe, ans)
            flag = 1
            ans += 1
            q = []
        else:
            if flag == 1:
                q = []
            else:
                q.pop()
        toBe += 1
        
sys.stdout.write(str(ans) + "\n")

from collections import deque
import sys

n = int(input())

q = deque([])
toBe = 1
ans = 0

flag = 0

inp = [0] * (n * 2)

for i in range(2 * n):
    inp[i] = sys.stdin.readline().strip()

for i in range(2 * n):
    s = inp[i].split()
    if len(s) == 2:
        k = int(s[1])
        q.append(k)
        if len(q) == 1:
            continue
        if k != q[-2] - 1:flag = 0
    else:
        #print(toBe, flag, ans)
        if q and toBe != q[-1]:
            #print(q, toBe, ans)
            flag = 1
            ans += 1
            q = []
        else:
            if flag == 1:
                q = []
            else:
                q.pop()
        toBe += 1
        
sys.stdout.write(str(ans) + "\n")

n = int(input())
c = 1
sorts = 0
boxes = []

for _ in range(2 * n):
    s = input()
    if s[0] == 'a':
        boxes.append(int(s[4:]))
    else:
        if boxes:
            if boxes[-1] != c:
                boxes = []
                sorts += 1
            else:
                boxes.pop()
        c += 1
print(sorts)


n = int(input())
indexToDel = 1
stack = [];
count = 0;
for i in range(n*2):
    line = input().split()
    if line[0] == 'remove':
        if len(stack) != 0:
            if stack[-1] == indexToDel:
                stack.pop();
            else:
                count+=1
                stack = []
        indexToDel+=1
    else:
        stack.append(int(line[1]))
        
print(count)

n = int(input())
mas = []
current = 1
count = 0

for i in range(2 * n):
    instruct = input().split()
    if instruct[0] == 'add':
        mas.append(int(instruct[1]))
    else:
        if len(mas) > 0:
            if mas[-1] == current:
                mas.pop()
            else:
                mas = []
                count += 1

        current += 1
print(count)


from heapq import heappush, heappop

n = int(input())
heap = []
ans = 0
last_added = []
for i in range(2*n):
    c = input()
    if c == "remove":
        out = heappop(heap)
        if len(last_added):
            if out != last_added[-1]:
                ans += 1
                last_added = []
            else:
                last_added.pop()
    else:
        b = int(c.split()[1])
        last_added.append(b)
        heappush(heap, b)
print(ans)


n = int(input())
pointer = 1
series = [0]*n
stack = []

reset = 0
for i in range(1,(n*2)+1):
    inp = input().split(' ')
    if inp[0] == 'add':
        number = int(inp[1])
        stack.append(number)        
    if inp[0] == 'remove':
        if len(stack) == 0:
            pointer +=1    
        elif stack[-1] == pointer:
            del stack[-1]
            pointer += 1
        else:    
            reset += 1
            stack = []
            pointer += 1
print(reset)


"""
	Author		: Arif Ahmad
	Date  		: 
	Algo  		: 
	Difficulty	: 
"""
from sys import stdin, stdout

def main():
	n = int(stdin.readline().strip())
	a = [0 for i in range(n + 1)]

	top = -1
	reordered = 0
	toRemove = 1
	for x in range(n + n):
		cmmd = stdin.readline().strip()
		if cmmd[0] == 'a':
			k = int(cmmd.split(' ')[1])
			top += 1
			a[top] = k
		else:
			if toRemove == a[top] or top == -1:
				top = max(top-1, -1)
			else:
				top = -1
				reordered += 1
			toRemove += 1

	stdout.write(str(reordered) + '\n')



def __starting_point():
    main()

__starting_point()

# Time   : 2017-6-26 14:30
# Auther : Anjone
# URL : http://codeforces.com/contest/821/problem/C


ans = 0
num = 1
stack = []
n = int(input())
for i in range(2*n):
	s = input()
	if s.find("add") != -1:
		stack.append(int(s.split()[1]) )
	else:
		if len(stack) != 0 and stack[-1] != num:
			stack = []
			ans+=1
		if len(stack):
			stack.pop()
		num += 1
print(ans)



n=int(input())
list=[]
ans=0
ptr=1
for i in range(2*n):
    s=input()
    if(s[0]=='a'):
        list.append(int(s[4:]))
    else:
        if(len(list)==0):
            ptr+=1
        elif list[-1]==ptr:
            list.pop()
            ptr+=1
        else:
            list=[]
            ans+=1
            ptr+=1
            
print(ans)
        


def remove():
    nonlocal c,tot,s
    c+=1
    if not s:   return
    elif s.pop()==c-1:  return
    tot,s=tot+1,[]
s,tot,c=[],0,1
for _ in range(int(input())*2):
    cmd= list(input().split())
    if cmd[0]=='add':
        s.append(int(cmd[1]))
    else:   remove()
print(tot)


def main():
    N=int(input())
    Q=2*N
    stack=[]
    curr=1
    ans=0
    for _ in range(Q):
        A=input().strip().split(' ')
        if len(A)>1:
            num=int(A[1])
            stack+=[num]
        else:
            if stack!=[]:
                if stack[-1]==curr:
                    stack.pop()
                else:
                    ans+=1
                    stack=[]
            curr+=1
    print(ans)        
main()

'''input
3
add 1
remove
add 2
add 3
remove
remove
'''
n = int(input())
c = 1
l = []
t = 0
for _ in range(2*n):
	i = input().split()
	if i[0] == "add":
		l.append(int(i[1]))
	else:
		if l:
			if l[-1] == c:
				l.pop()
			else:
				t += 1
				l = []
		c += 1
print(t)




n=int(input())
st=[]
ans=0
c=0
for _ in range(2*n):
	s=input()
	if s=="remove":
		if len(st)==0 or c+1==st[-1] :
			if len(st)!=0:
				st.pop(-1)
			c+=1
		else:
			ans+=1
			c+=1
			st=[]	
	else:
		st.append(int(s[4:]))
	#print (st,end=" ")
	#print (ans)	
print (ans)	


n = int(input())
cnt = 1
ans = 0
l = list()
for i in range(2*n):
    s = input()
    if(s[0]=='a'):
        l.append(int(s[4:]))
    else:
        if(len(l)==0):
            pass
        elif(l[-1]==cnt):
            l.pop()
        else:
            ans += 1
            l = list()
        cnt += 1
print(ans)


n_boxes = int(input())

stack = [] #stack
b=1
count = 0  #count

for i in range(2*n_boxes):
  input_string = input().split(' ')
  #check command type
  if len(input_string) == 2:  #add
    x = int(input_string[1])
    stack.append(x)
  else: #remove
    if len(stack)!=0:
      if stack[-1] == b:
        stack.pop()
      else:
        count += 1
        stack = []
    b+=1
      
print(count)

from collections import deque
queue = deque()
ans=0
cou=1
n = int(input())
for j in range(2*n):
    a=input().split()
    if a[0] == 'add':
        queue.append(int(a[1]))
    else:
        if queue:
            if cou == queue[-1]:
                
                queue.pop()
            else:
                ans+=1
                queue=deque()
                
        cou+=1
print(ans)
            


import sys

S = []
A=set()
cnt = 0
r = 0
for i in range(2*int(sys.stdin.readline().strip())):
    cmd = sys.stdin.readline().strip().split()
    if cmd[0] == "add":
        S.append(int(cmd[1]))
    else:
        r += 1
        if S == []:
            if r in A:
                continue
        elif S[-1] == r:
            S.pop()
            continue
        else:
            cnt += 1
            A.union(S)
            S = []

print(cnt)


n=int(input())
st=[]
ans,now=0,1
for i in range(2*n):
    s=input()
    if s[0]=="a":
        st.append(int(s[4:]))
    else:
        if len(st)==0:
            now+=1
        else:
            if st[-1]==now:
                now+=1
                st.pop()
            else:
                st=[]
                ans+=1
                now+=1
print(ans)