n = int(input()) A = [] B = [] for _ in range(n): a, b = map(int, input().split()) A.append(a) B.append(b) nex = [-1] * n j = -1 tf = [True] * n for i in range(n - 1, -1, -1): if B[i] == 2: nex[j] = i tf[i] = False elif B[i] == 1: j = i if A[i] == 1: nex[i + 1] = i tf[i] = False for i in range(n): if tf[i]: x = i while x != -1: print(x + 1) x = nex[x]