using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static System.Console; namespace yukicoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int m = int.Parse(Console.ReadLine()); int ans = 0; for (int i = 0; i < m; i++) { var s = Console.ReadLine().Split().Select(int.Parse).ToArray(); var s1 = s[0]; var s2 = s[1]; if (n == s1) { n = s2; } else if (n == s2) { n = s1; } } Console.WriteLine(n); } } }