c = [0,0,0] c[int(input())-1] = 1 for i in range(int(input())): a,b = (int(x)-1 for x in input().split()) c[a],c[b] = c[b],c[a] print(c.index(1)+1)