import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No26{ public static void main(String[] args) { try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int cupNumAns = Integer.parseInt(br.readLine()); int changeTimes = Integer.parseInt(br.readLine()); System.out.println(changeCup(br, cupNumAns, changeTimes)); } catch(IOException e){ e.getStackTrace(); } catch(NumberFormatException e){ e.getStackTrace(); } } public static int changeCup(BufferedReader br, int n, int m) throws IOException, NumberFormatException{ for(int i=0; i < m; i++){ String[] str = br.readLine().split(" "); int[] cupNum = new int[2]; for(int j=0; j < 2; j++) cupNum[j] = Integer.parseInt(str[j]); if(n == cupNum[0]) n =cupNum[1]; else if(n == cupNum[1]) n = cupNum[0]; } return n; } }