using System; using System.Diagnostics; namespace yukicoder { class Program { static void Main(string[] args) { //印が付いたカップの位置 int N = int.Parse(Console.ReadLine()); //カップを入れ替える回数 int M = int.Parse(Console.ReadLine()); //現在の印の位置 string x = N.ToString(); //入れ替える回数分ループ for (int i = 0; i < M; i++) { string[] str = Console.ReadLine().Split(' '); //xと入れ替える位置が同じなら if (x == str[0]) { //入れ替える x = str[1]; } else if(x==str[1]) { x = str[0]; } } Console.WriteLine(x); } } }