using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ForYukicoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //あたりカップ位置 int M = int.Parse(Console.ReadLine()); //入れ替えた回数 string[] str; int[] P = new int[M]; int[] Q = new int[M]; for (int i = 0; i < M; i++) { str = Console.ReadLine().Split(); P[i] = int.Parse(str[0]); Q[i] = int.Parse(str[1]); } //------------------------------ for (int i = 0; i < M; i++) { if (P[i] == N) { N = Q[i]; } else if(Q[i] == N) { N = P[i]; } } Console.WriteLine(N); } } }