n=int(input())
m=int(input())
l=[0,1,2,3]
for i in range(m):
    s,t=map(int,input().split())
    l[s]=t
    l[t]=s
print(l[1])