n = gets.to_i m = gets.to_i m.times do |x| s = gets.split.map(&:to_i) if n == s[0] n = s[1] elsif n == s[1] n = s[0] end end puts n