import java.util.*; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); boolean[] cup = {false, false, false}; int first = scanner.nextInt() - 1; int shuffle = scanner.nextInt(); int l = 0; int r = 0; cup[first] = true; for(int i = 0; i < shuffle; i++){ l = scanner.nextInt() - 1; r = scanner.nextInt() - 1; if(first == l){ cup[first] = false; cup[r] = true; first = r; }else if(first == r){ cup[first] = false; cup[l] = true; first = l; } } for(int i = 0; i < 3; i++){ if(cup[i] == true){ System.out.println(i + 1); } } } }