N=int(input()) from collections import deque d=deque() A=[] for i in range(N): a,b=map(int,input().split()) A.append((a,b)) C=[];c=10**10 for i in range(N-1,-1,-1): a,b=A[i] if b==1: c=i C.append(c) C=C[::-1] D=[-1]*N P=[-1]*N for i in range(N): a,b=A[i] if a==1: D[i+1]=i P[i]=i+1 if b==2: D[C[i]]=i P[i]=C[i] ans=[] for i in range(N): if P[i]==-1: now=i print(now+1) while True: nex=D[now] if nex==-1: break print(nex+1) now=nex