n = gets.chomp.to_i
s = []
t = []
for i in 0..n-1
    song,time = gets.chomp.split
    s << song
    time = time.to_i
    t << time
end
x = gets.chomp
flag = 0
ans = 0
for i in 0..n-1
    if s[i] == x
        flag = 1
    elsif flag == 1 
        ans += t[i]
    end
end

puts ans