def search_end(arr, start)
  now = start

  arr.each do |row|
    if row[1] == now
      now = row[2]
    elsif row[2] == now
      now = row[1]
    end
  end

  now
end

loop do
  n, m, a = gets.chomp.split(" ").map(&:to_i)
  break if n + m + a == 0
  amida = []

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

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