n = gets.to_i
hash = {}
n.times do
  s,t = gets.split(' ')
  hash[s] = t.to_i
end
x = gets.chomp
sum = 0
check = 0
hash.each do |k,v|
  if k == x || check == 1
    check = 1
    if k != x
      sum += v
    end
  end
end
puts sum