using System; using System.Diagnostics; namespace yukicoder { class Program { static void Main(string[] args) { //カップ //int[] n = { 1, 2, 3 }; //印が付いたカップの位置 int N = int.Parse(Console.ReadLine()); //カップを入れ替える回数 int M = int.Parse(Console.ReadLine()); int[] a = new int[2]; //入れ替える回数分ループ for (int i = 0; i < M; i++) { string[] str = Console.ReadLine().Split(' '); //入れ替える位置の番号 for (int j = 0; j < 2; j++) { int A = int.Parse(str[j]); a[j] = A; //Debug.WriteLine(a[j]); } //Nと入れ替える位置が同じなら if (N == a[0]) { //入れ替え for (int j = 1; j <= 3; j++) { //a配列にn配列と同じ数字があれば if (a[0] == j) { //入れ替える int temp = a[0]; a[0] = a[1]; a[1] = temp; break; } //if (j == 2) //{ // Debug.Write(n[j]); //} } } else if(N==a[1]) { for(int j=1;j<=3;j++) { if (a[1] == j) { int temp = a[1]; a[1] = a[0]; a[0] = temp; break; } } } } //現在印が付いたカップの位置 for(int i=1;i<=2;i++) { if(N==a[i-1]) { if (i == 2) { Console.WriteLine(i+1); break; } Console.WriteLine(i); break; } if(N!=a[i]) { Console.WriteLine(N); break; } } } } }