n = int(input()) m = int(input()) ans = n for i in range(m): x,y = map(int,input().split()) if ans != x and ans != y: continue ans = x+y-ans print(ans)