loop do
    n, m, a = gets.split.map(&:to_i)
    break if n == 0 && m == 0 && a == 0
    d = m.times.map{gets.split.map(&:to_i)}
    d.sort! { |a, b| b[0] <=> a[0]}
    pos = 1
    d.each do |dd|
        if dd[1] == pos
            pos = dd[2]
        elsif dd[2] == pos
            pos = dd[1]
        end
    end
    puts pos
end