from collections import defaultdict from sys import stdin def main(): input = lambda: stdin.readline()[:-1] N = int(input()) AB = [tuple(input().split()) for _ in [0] * N] student = defaultdict(int) for a, b in AB: student[a] = -1 ans = [] for a, b in AB: if not student[b]: ans.append(b) student[b] = 1 print(*ans, sep='\n') main()