using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int ans = int.Parse(Console.ReadLine()); long n = long.Parse(Console.ReadLine()); for (long i = 0; i < n; i++) { int[] change = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray(); if (ans == change[0]) { ans = change[1]; } } Console.WriteLine(ans); Console.Read(); } }