cap = ["bl", "x", "x", "x"] N = int(input()) cap[N] = "o" M = int(input()) for i in range(M): p, q = input().split() p, q = int(p), int(q) cap[p], cap[q] = cap[q], cap[p] for i in range(len(cap)): if cap[i] == "o": print(i)