N = int(input()) M = int(input()) ans = N for i in range(M): a, b = map(int, input().split()) if a == ans: ans = b elif b == ans: ans = a print(ans)