s=[1,2,3] place=int(input()) n=input() for q in range(int(n)): x,y=map(int,input().split()) s[x-1],s[y-1]=s[y-1],s[x-1] if place==int(s[0]): print(1) elif place==int(s[1]): print(2) else: print(3)