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