N =int(input()) M =int(input()) for q in range(M): l,r = map(int,input().split()) if(l==N): N=r elif(r==N): N=l print(N)