import java.util.Scanner; public class Main { public static void main(String[] a) { Scanner s=new Scanner(System.in); int[] C=new int[4];C[s.nextInt()]=1; s.nextInt(); while(s.hasNext()){ int i=s.nextInt(),j=s.nextInt(),t=C[i]; C[i]=C[j];C[j]=t; } System.out.println(C[1]>0?1:C[2]>0?2:3); } }