# 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 cups[move[j][0]] == 'true': cups[move[j][0]] = 'false' cups[move[j][1]] = 'true' elif cups[move[j][1]] == 'true': cups[move[j][0]] = 'true' cups[move[j][1]] = 'false' else: continue for l in range(1,4): if cups[l] == 'true': print(l) break else: continue