def main(): N = int(input()) M = int(input()) for x in range(M): p, q = map(int, input().split()) if N == p: N = q elif N == q: N = p print(N) if __name__ == '__main__': main()