import java.util.ArrayDeque; import java.util.Arrays; import java.util.Queue; import java.util.Scanner; public class Main { private int now; private int n; public void setNow(int now){ this.now = now; } public void setN(int n){ this.n = n; } public int getNow(){ return this.now; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); Main m = new Main(); int now = sc.nextInt(); m.setNow(now); int n = sc.nextInt(); m.setN(n); int a,b; for(int i = 0;i < n;i++){ a = sc.nextInt(); b = sc.nextInt(); if(a == m.getNow()){ m.setNow(b); }else if(b == m.getNow()){ m.setNow(a); } } System.out.println(m.getNow()); } }