# -*- coding:utf-8 -*- columnCuount = int(input()) barCount = int(input()) barMap = [] for i in range(barCount): barMap.append([int(j) - 1 for j in input().rstrip().split(" ")]) numList = [[i, i] for i in range(columnCuount)] def getGoal(column): current = column for (f, t) in barMap: if t == current: current = f elif f == current: current = t return current moveList = [getGoal(i) for i in range(columnCuount)] for i in range(1000000): tmp = sorted([[moveList[i], v] for (i, v) in numList]) if len([[i,v] for (i,v) in tmp if i != v]) == 0: print(str(i+1)) exit(0) numList = tmp