N = gets.to_i

playlist = []
N.times do 
  song_set = gets.split()
  song = song_set[0]
  time = song_set[1]
  playlist << {"#{song}": "#{time}"}
end

sleep_name = gets.chomp.to_s

sleep_song_count = 0
playlist.each_with_index do |array, index|
  if sleep_name == array.keys.first.to_s
    sleep_song_count = index + 1
  end
end

left_over_list = playlist.drop(sleep_song_count)

total_sleep_time = 0
left_over_list.each do |array|
  total_sleep_time += array.values.first.to_i
end

puts total_sleep_time
