import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(buff.readLine()); int M = Integer.parseInt(buff.readLine()); for(int i = 0; i < M; ++i){ String[] str = buff.readLine().split(" "); int[] box = new int[2]; boolean flag = false; for(int j = 0; j < 2; ++j){ box[j] = Integer.parseInt(str[j]); if(N == box[j]){ flag = true; } } if(flag){ if(N == box[0]){ N = box[1]; }else{ N = box[0]; } } } System.out.println(N); } catch (NumberFormatException e) { } catch (IOException e) { } } }