def search_end(arr, start)
  now = start
  
  arr.each do |row|
    if row[1] == now
      now = row[2]
    end
  end
  
  now
end

n, m, a = gets.chomp.split(" ").map(&:to_i)
amida = []

m.times do
  amida << gets.chomp.split(" ").map(&:to_i)
end

puts search_end(amida.sort { |a, b| b[0] <=> a[0] }, a)