N= int(input()) M= int(input()) shuffle= [list(map(int, input().split())) for i in range(M)] def calc(N, shuffle): for a, b in shuffle: if N == a: N = b elif N == b: N = a print(N) calc(N, shuffle)