class Problem0026: def solve(this): n = int(input()) m = int(input()) for i in range(m): p,q = map(int, input().split()) if n == p: n = q elif n == q: n = p print(n) if __name__ == "__main__": problem = Problem0026() problem.solve()