N = gets.to_i
ary = N.times.map{gets.split.map(&:to_s)}
S = []
T = []
ary.each do|s,t|
  S << s
  T << t.to_i
end

X = gets.chomp

if T[S.index(X)+1..N-1] == []
  puts 0
else
  puts T[S.index(X)+1..N-1].inject(:+)
end



  

