fs=int(input()) ls=['x']*3 ls[fs-1]='o' n=int(input()) for i in range(n): chls=list(map(int,input().split())) sh=[chls[0]-1,chls[1]-1] buf=ls[sh[0]] ls[sh[0]]=ls[sh[1]] ls[sh[1]]=buf print(ls.index('o')+1)