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