class Line
  attr_accessor :h,:p,:q
  def initialize(h,p,q)
    @h=h
    @p=p
    @q=q
  end
end

loop do
  n,m,a = gets.split.map(&:to_i)
  break if(n|m|a)==0
  ls =[]
  m.times do
    h,p,q = gets.split.map(&:to_i)
    ls << Line.new(h,p,q)
  end
  ls.sort!{|b,c|c.h-b.h}
  ls.each do |line|
    p = line.p
    q = line.q
    if a==p
      a=q
    elsif a==q
      a=p
    end
  end
  p a
end