ck = int(input()) count = int(input()) for i in range(count): l = list(map(int, input().split())) if ck in l: if l[0] == ck: ck = l[1] else: ck = l[0] print(ck)