N = gets.to_i
a = [0] * (N+1)
names = [""]
N.times do |i|
    name, t = gets.chomp.split(/\s/)
    a[i+1] = a[i] + t.to_i
    names << name
end

title = gets.chomp

s = 0
names.each_with_index do |name, idx|
  if title == name
    s = idx
    break
  end
end
puts a[N] - a[s]