n = gets.to_i
title = []
sec = []
for i in 0..n-1 do
  a,b = gets.split(" ")
  title.push(a)
  sec.push(b.to_i)
end
x = gets.chomp
flag = false
cnt = 0
for i in 0..n-1 do
  if flag then
    cnt += sec[i]
  elsif x==title[i] then
    flag = true
  end
end
puts(cnt)