N = int(input()) M = int(input()) bs = [False] * 3 bs[N-1] = True for _ in range(M): P, Q = map(lambda x: int(x)-1, input().split()) bs[P], bs[Q] = bs[Q], bs[P] ans = bs.index(True) print(ans+1)