n = gets.to_i
songs = []
n.times do |i|
  s , t = gets.chomp.split
  songs[i] = [s, t.to_i]
end
x = gets.chomp
# p x
# p n, songs , x
ans = 0
f = songs.find_index {|n| n[0] == x} + 1
songs[f..-1].each do |i|
  ans += i[1]
end
puts ans
