n = int(input()) m = int(input()) lst = [1, 2, 3] for i in range(m): x, y = map(int, input().split()) tmp=lst[x-1] lst[x-1]=lst[y-1] lst[y-1]=tmp print(lst.index(n)+1)