N = int(input()) M = int(input()) PQ = [list(map(int, input().split(' '))) for _ in range(M)] for i in range(M): if N == PQ[i][0]: N = PQ[i][1] elif N == PQ[i][1]: N = PQ[i][0] else: continue print(N)