import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) m=int(input()) for _ in range(m): p,q=map(int,input().split()) if n==p: n=q elif n==q: n=p else: continue print(n)