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

class Heap
  def initialize
    @nodes = []
  end

  def push(h, p)
    @nodes << Node.new(h, p)
    c = @nodes.size-1
    p = (c-1)/2

    while c != 0 && @nodes[p].h < h
      @nodes[c], @nodes[p] = @nodes[p], @nodes[c]
      c, p = p, (p-1)/2
    end
  end

  def pop
    res = @nodes.first
    if @nodes.size == 1
      @nodes.pop
      return res
    end

    @nodes[0] = @nodes.pop
    p = 0
    c = 2*p+1

    while c < @nodes.size && @nodes[p].h < @nodes[c].h
      if c+1 < @nodes.size && @nodes[c].h < @nodes[c+1].h
        c = c+1
      end
      @nodes[p], @nodes[c] = @nodes[c], @nodes[p]
      p, c = c, 2*c+1
    end
    return res
  end

  def size
    @nodes.size
  end
end

while true do
  n, m, a = gets.split.map(&:to_i)
  break if n|m|a == 0

  nums = []
  (1..n).each{ |i| nums << i }
  heap = Heap.new
  m.times do
    h, p, q = gets.split.map(&:to_i)
    heap.push(h, p-1)
  end

  until heap.size == 0
    p = heap.pop.p
    nums[p], nums[p+1] = nums[p+1], nums[p]
  end

  nums.each_with_index do |num, i|
    if num == a
      puts i+1
      break
    end
  end
end