loop do
    n, m, a = gets.chomp.split.map(&:to_i)

    break if n == 0 && m == 0 && a == 0

    hl = []

    m.times do
        h, p, q = gets.split.map(&:to_i)
        hl.push [h, p, q]
    end

    hl = hl.sort_by(&:first).reverse

    ans = a

    for i in 0..m-1
        if ans == hl[i][1]
            ans = hl[i][2]
        elsif ans == hl[i][2]
            ans = hl[i][1]
        end
    end
    puts ans

end
