n=int(input())
ls=[i for i in range(n)]
for i in range(n-1-1):
    u,v=map(int,input().split())
    if min(u,v) in ls:
        ls.remove(min(u,v))
        print(min(u,v))
    print(ls[0])
    ls.remove(ls[0])
