n = gets.chomp.to_i

playlist = []
sleep = ""
while line = gets
  splited = line.split(" ")
  if splited.size != 2
    sleep = splited[0]
    break
  end

  name = splited[0]
  len = splited[1].to_i

  playlist << {name: name, len: len}
end

t = 0
neteru = false
playlist.each do |song|
  t += song[:len] if neteru
  neteru = true if song[:name] == sleep
end

puts t