n = STDIN.gets.to_i

ss = n.times.inject([]) do |s, _|
  s << STDIN.gets.split
  s
end

x = STDIN.gets.chomp

t = 0
ss.reverse.find {|s|
  if s[0] == x
    true
  else
    t += s[1].to_i
    false
  end
}

puts t