# coding:utf-8 cups = {1:'false',2:'false',3:'false'} start_cup = int(input()) cups[start_cup] = 'true' shuffle_count = int(input()) move = [] for i in range(shuffle_count): move.append(list(map(int,input().split()))) for j in range(shuffle_count): if move[j][0] == 'true': cups[move[j][0]] = 'false' cups[move[j][1]] = 'true' elif move[j][1] == 'true': cups[move[j][0]] = 'true' cups[move[j][1]] = 'false' else: continue print(cups) for l in range(1,3): if cups[l] == 'true': print(l) break else: continue