n = gets.to_i

ss = []
ts = []
n.times do
  s,t = gets.split
  ss.push(s)
  ts.push(t.to_i)
end

x = gets.chomp

start = ss.index(x)
if start == n-1
  puts 0
else
  puts ts[start+1..-1].inject(:+)
end
