loop do
  n, m, a = gets.chomp.split.map &:to_i
  break if n == 0 && m == 0 && a == 0

  lines = Array.new
  n.times do |i|
    lines[i] = Array.new
  end

  m.times do
    h, p, q = gets.chomp.split.map &:to_i
    lines[p-1][h] = q-1
    lines[q-1][h] = p-1
  end

  current = a-1
  1000.downto(1) do |h|
    current = lines[current][h] unless lines[current][h].nil?
  end

  puts current+1
end