# coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read n = int(readline()) q = int(readline()) r = [0,0,0,0] r[n] = 1 for _ in range(q): z,w = map(int,readline().split()) r[z],r[w] = r[w],r[z] print(r.index(1))