N = int(input()) M = int(input()) P = [0] * M Q = [0] * M current = N for i in range(M): P[i], Q[i] = map(int,input().split()) for i in range(M): if P[i] == current: current = Q[i] elif Q[i] == current: current = P[i] print(current)