using System.Collections.Generic; using System; using System.Linq; using System.Drawing; namespace yukicoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var M = int.Parse(Console.ReadLine()); int M1, M2 ; string sss = ""; string[] strings = new string[] {"1" , "2" , "3"}; for (int i = 0; i < M; i++) { var O = Console.ReadLine().Split(" "); M1 = int.Parse(O[0]); M2 = int.Parse(O[1]); var temp = strings[M1 - 1]; strings[M1 - 1] = strings[M2 - 1]; strings[M2 - 1] = temp; } string str = N.ToString(); for(int c = 0; c < strings.Length; c++) { sss += strings[c]; } int ans = sss.IndexOf(str); Console.WriteLine(ans + 1); } } }