N = int(input()) AB = [input().split() for _ in range(N)] D = set() for a,b in AB: D.add(a) for a,b in AB: if b not in D: print(b) D.add(b)