n = gets.chomp.to_i
s = []
t = []
for i in 0..(n-1)
    s[i],t[i] = gets.split(" ")
end
t = t.map!(&:to_i)
x = gets.chomp
cnt = s.index(x)
lesult = t.slice((cnt+1)..(-1)).inject(:+)
if lesult == nil
    puts 0
else 
    puts lesult
end