N = input() M = input() c = [0] * 4 c[N] = 1 for i in range(M): p, q = map(int, raw_input().strip().split(" ")) c[p], c[q] = c[q], c[p] for i in range(1, 4): if c[i] > 0: print(i)