n = int(input()) m = int(input()) pos = n for _ in range(m): p, q = map(int, input().split()) if pos == p: pos = q elif pos == q: pos = p print(pos)