n=int(input())
m=int(input())
a=list(range(3))
for i in range(m):
	x,y=map(int,input().split())
	a[x-1]=y-1
	a[y-1]=x-1
print(a.index(n-1)+1)