### constant

MAX_H = 1000

### main

loop do
  n, m, a = gets.split.map(&:to_i)
  #p [n, m, a]
  break if n == 0

  hls = Array.new(n + 1){Array.new(MAX_H + 1){0}}
  maxh = 0
  
  m.times do
    h, pi, qi = gets.split.map(&:to_i)
    #p [h, pi, qi]

    hls[pi][h] = qi
    hls[qi][h] = pi
    maxh = h if maxh < h
  end

  x = a
  y = maxh

  while y >= 1
    x = hls[x][y] if hls[x][y] > 0
    y -= 1
  end

  puts x
end