N=input() M=int(input()) for i in range(M): L=input().split() if N in L: L.remove(N) N=L[0] print(N)