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