N=int(input()) M=int(input()) for _ in range(M): P,Q=map(int,input().split()) if P==N:N=Q print(N)