import java.util.Scanner; public class no26{ public static void main(String... args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(),m = scan.nextInt(),p,q,tmp; int res[] = new int[3]; res[n-1]++; for(int i = 0; i < m; i++){ p = scan.nextInt(); q = scan.nextInt(); p--; q--; tmp = res[p]; res[p] = res[q]; res[q] = tmp; } for(int i = 0; i < 3; i++){ if(res[i] == 1){ System.out.println(i+1); break; } } } }