package yukicoder.No26; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int circle = Integer.parseInt(sc.next()); int M = Integer.parseInt(sc.next()); for (int i = 0; i < M; i++) { int b = Integer.parseInt(sc.next()); int a = Integer.parseInt(sc.next()); if (b == circle) { circle = a; } } System.out.println(circle); } }