init = input() for _ in range(int(input())): shuffle = input().split() if init in shuffle: shuffle.remove(init) init = shuffle[0] print(init)