package me.yukicoder.lv1; import java.util.Scanner; public class No0026 { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in);) { int N = sc.nextInt();// 最初に○印が付いているカップ int M = sc.nextInt(); int mark = N; for (int i = 0; i < M; i++) { int p = sc.nextInt(); int q = sc.nextInt(); if (mark == p) { mark = q; } else if (mark == q) { mark = p; } } System.out.println(mark); } } }