n = int(input()) m = int(input()) ls = [] for i in range(m): p, q = map(int, input().split()) ls.append((p, q)) pos = n for p, q in ls: if pos == p: pos = q elif pos == q: pos = p print(pos)