require 'pp'

n = gets.chomp!.to_i
s_n = Array.new(n)
t_n = Array.new(n)
n.times do |i|
    s, t = gets.split
    s_n[i] = s
    t_n[i] = t.to_i
end
x = gets.chomp!

ok = false
sum = 0
s_n.each_with_index do |s, i|
    if s_n[i] == x
        ok = true
        next
    end

    if ok
        sum += t_n[i]
    end
end

puts sum
