N=gets.to_i

name=Array.new(N)
time =Array.new(N)
ans=0
sum=0

for num in 0..N-1
  array=  gets.split(" ")
  name[num]=array[0].to_s
  time[num]=array[1].to_i
end

S=gets.to_s

for num in 0..N-1
  if name[num]==S
    ans=num
    break
  end
end

for num in ans+1..N-1
  	sum=sum+time[num]
end


puts sum