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