current = int(input()) num = int(input()) for i in range(num): pos = list(map(int, input().split())) if current in pos: pos.remove(current) current = pos[0] print(current)