n = int(input()) l = [0]*4 l[n] = 1 m = int(input()) for i in range(m): i,j = map(int,input().split()) l[i],l[j] = l[j],l[i] print(l.index(1))