import java.util.Scanner; class No_26 { public static void main(String args[]) { Scanner stdIn = new Scanner(System.in); int []cup = new int [3]; int num = stdIn.nextInt(); int shuffle = stdIn.nextInt(); for (int i = 0; i < 3; i++) { cup[i] = 0; } cup[num-1] = 1; for (int i = 0; i < shuffle; i++) { int swap1 = stdIn.nextInt(); int swap2 = stdIn.nextInt(); int tmp = cup[swap1-1]; cup[swap1-1] = cup[swap2-1]; cup[swap2-1] = tmp; } for (int i = 0; i < 3; i++) { if ( cup[i] == 1 ) { System.out.println(i+1); break; } } } }