# -*- coding: utf-8 -*- def main(): N = int(input()) M = int(input()) res = N for i in range(M): l, r = map(int, input().split()) if res == l: res = r elif res == r: res = l print(str(res) + "\n") if __name__ == '__main__': main()