import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(input()) M = int(input()) PQ = [[int(x) for x in input().split()] for _ in range(M)] for p, q in PQ: if p == N: N = q elif q == N: N = p print(N) if __name__ == '__main__': main()