import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): ok = set() ng = set() name_to_i = {} n = int(input()) for i in range(n): ng_name, ok_name = input().split() ok.add(ok_name) ng.add(ng_name) if ng_name not in name_to_i: name_to_i[ng_name] = i * 2 if ok_name not in name_to_i: name_to_i[ok_name] = i * 2 + 1 ok -= ng for name in sorted(ok, key=lambda x: name_to_i[x]): print(name) main()