max = gets.to_i
songs = []
for num in 0...max do
 songs.push(gets.split)
end
x = gets.chomp

sleep_num = 0

for i in 0...max do
  if songs[i][0] == x then
    sleep_num = i+1
  end
end

time = 0

for num in sleep_num...max do
  time += songs[num][1].to_i
end

print time