n = int(input()) m = int(input()) for i in range(m): A = set(map(int, input().split())) if n in A: n = (A - set([n])).pop() print(n)