import java.io.*; import java.util.*; import java.util.stream.*; // 処理 class Process { private PrintWriter printWriter; private int N; private int[] P; private int[] Q; Process(PrintWriter printWriter, int N, int[] P, int[] Q) { this.printWriter = printWriter; this.N = N; this.P = P; this.Q = Q; } // 結果を出力 void printResult() throws IOException { int markedIndex = N; for(int i = 0; i < P.length; i++) { if(markedIndex == P[i]) { markedIndex = Q[i]; } else if(markedIndex == Q[i]) { markedIndex = P[i]; } } printWriter.println(markedIndex); } } public class Main { public static void main(String[] args) throws IOException { var bufferedReader = new BufferedReader(new InputStreamReader(System.in)); var printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); // 入力 int N = Integer.parseInt(bufferedReader.readLine().trim()); int M = Integer.parseInt(bufferedReader.readLine().trim()); var input = new int[2]; var P = new int[M]; var Q = new int[M]; for(int m = 0; m < M; m++) { input = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray(); P[m] = input[0]; Q[m] = input[1]; } // Process クラスで処理を行う var process = new Process(printWriter, N, P, Q); process.printResult(); // 各ストリームを閉じる // 出力ストリームを閉じるときに標準出力に文字を出力する bufferedReader.close(); printWriter.close(); } }