N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] nex = dict() pre = -1 for i, (A, B) in enumerate(AB): if A == 1: nex[i+1] = i if B == 2: pre = i elif B == 1: nex[i] = pre ans = [] for i, (A, B) in enumerate(AB): if A != 1 and B != 2: ans.append(i) now = i while now in nex: now = nex[now] ans.append(now) for a in ans: print(a+1)