n = gets.to_i

playlist = []
n.times do
  x, y = gets.split(" ")
  playlist.push({"#{x}" => y.to_i })
end
n = gets.chomp!
index = playlist.index { |item| item.key? n }
ans = 0
playlist.shift(index + 1)
playlist.each do |item|
  ans += item.values.first
end

puts ans
