# frozen_string_literal: true

n = gets.to_i
s = []
t = []
n.times do
  st = gets.split
  s.push st[0].chomp
  t.push st[1].to_i
end
x = gets.chomp
flag = false
sum = 0
0.upto(n - 1) do |i|
  sum += t[i] if flag

  flag = true if s[i] == x
end
puts sum
