N=int(input()) stack=[] for i in range(1,N+1): A,B=map(int,input().split()) if A==0: if B==0: print(i) while len(stack) and stack[-1][0]==1: print(stack.pop()[1]) elif B==1: print(i) print(stack.pop()[1]) else: stack.append((2,i)) else:stack.append((1,i)) while len(stack): print(stack.pop()[1])