using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace template { class Program { static void Main(string[] args) { int ret = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == ret) ret = x[1]; else if (x[1] == ret) ret = x[0]; } Console.WriteLine(ret); } } }