loca = int(input()) n = int(input()) for i in range(n): a, b = map(int, input().split()) if loca == a: loca = b elif loca == b: loca = a print(loca)