import java.util.Scanner; import java.util.stream.Stream; public class No00000026_Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = Integer.parseInt(scan.nextLine()); int m = Integer.parseInt(scan.nextLine()); for(int i = 0; i < m; i++) { int[] arr = Stream.of(scan.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); if(arr[0] == n) { n = arr[1]; } else if(arr[1] == n) { n = arr[0]; } } System.out.println(n); scan.close(); } }