n=gets.chomp.to_i
s=[]
t=[]
for i in 0..n-1
  s[i],t[i]=gets.chomp.split(" ")
  t[i]=t[i].to_i
end
x=gets.chomp

for i in 0..n-1
  if s[i]==x
    ans=t[i+1..n-1].inject(:+)
  end
end
p ans unless ans.nil?
p 0 if ans.nil?