n = gets.to_i
playlist = []
playlist_time = []
n.times do
 song, playtime = gets.chomp.split()
 playlist.push(song)
 playlist_time.push(playtime.to_i)
end
x = gets.chomp!

if playlist[-1] == x
 puts(0)
else
 slep = playlist.index(x)
 puts(playlist_time[slep+1..-1].inject(:+))
end