n=int(input()) m=int(input()) cup=['×']*3 cup[n-1]='〇' for i in range(m): p,q=map(int,input().split()) m_1=cup[p-1] m_2=cup[q-1] cup[p-1]=m_2 cup[q-1]=m_1 print(cup.index('〇')+1)