N = int(input()) M = int(input()) a = [False] * 4 a[N] = True for _ in range(M): P,Q = list(map(int,input().split())) memo = a[P] a[P] = a[Q] a[Q] = memo for i in range(4): if a[i]: print(i)