N = int(input()) M = int(input()) for x in [list(map(int,input().split())) for x in range(M)]: if N in x: x.remove(N) N = x[0] print(N)