s=['x']*3 s[int(input())-1]='o' m=int(input()) for i in range(m): p,q=map(int,input().split()) p-=1;q-=1; (s[p],s[q])=(s[q],s[p]) for i in range(3): if s[i]=='o': print(i+1); break