class Bar
	def initialize(a)
		@h = a[0]
		@p = a[1]
		@q = a[2]
	end

	attr_accessor :h
	attr_accessor :p
	attr_accessor :q
end

loop do
	n, m, a = gets.split.map(&:to_i)
	if n == 0 && m == 0 && a == 0 then
		break
	end

	b = []

	m.times do
		b.push Bar.new(gets.split.map(&:to_i))
	end

	b.sort!{|a0, b0| b0.h <=> a0.h }

	m.times do |i|
		if b[i].p == a then
			a = b[i].q
		elsif b[i].q == a then
			a = b[i].p
		end
	end

	puts a
end