N = gets.chomp.to_i
a = Array.new(N)
b = Array.new(N)
for i in 0...N do
    str = gets.split
    a[i],b[i] = str[0], str[1].to_i
end
X = gets.chomp

answer = 0
f = 1
for i in 0...N do
    if f == 0
        answer += b[i]
    else
        if X == a[i]
            f = 0
        end
    end
end

puts answer