import java.util.*; public class ShuffleGame { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); try{ int Initial = scanner.nextInt(); //●の初期位置 int RepetitionNumber = scanner.nextInt(); //試行回数 for(int i = 0 ; i < RepetitionNumber ; i++){ int P = scanner.nextInt(); //Pを代入 int Q = scanner.nextInt(); //Qを代入 if(P == Initial){ Initial = Q; }else if(Q == Initial){ Initial = P; } } System.out.println(Initial); }catch(InputMismatchException e){ System.out.println("数値を入れてください。"); }catch(Exception EE){ System.out.println("想定外のエラーです。"); } } }