import java.io.*; import java.util.*; class Main26 { public static void out (Object o) { System.out.println(o); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int ans = Integer.parseInt(br.readLine()); int m = Integer.parseInt(br.readLine()); for (int i = 0; i < m; i++) { String[] line = br.readLine().split(" "); int p = Integer.parseInt(line[0]); int q = Integer.parseInt(line[1]); ans = ans == p ? q : ans == q ? p : ans; } out(ans); } }