N = gets.to_i

play_lists = N.times.map { 
  title, time = gets.chomp.split
  [title, time.to_i]
}
X = gets.chomp

sleep = false
ans = 0

play_lists.each do |s, t|
  if s == X
    sleep = true
  elsif sleep
    ans += t
  end
end

puts ans
