package yukicoder; import java.util.Scanner; public class Yuki26 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); int changeCount = scan.nextInt(); int changeCupArray[][] = new int [changeCount][2]; for (int i = 0; i < changeCount;i++) { for(int j = 0; j < 2; j++) { changeCupArray[i][j] = scan.nextInt(); } } scan.close(); int pastValue = num; for (int i = 0; i < changeCount;i++) { for(int j = 0; j < 2; j++) { if(changeCupArray[i][j] == pastValue ){ pastValue = changeCupArray[i][j]; } } } System.out.println(pastValue); } }