N = gets.chop.to_i

s = []
t = []

N.times do
  line = gets.chop.split
  s << line.shift
  t << line
  @s_new = s
  @t_new = t.flatten(1).map(&:to_i)
end

X = gets.chop.to_s

niwango_sleep = @s_new.find_index(X)

if niwango_sleep == 0
  puts @t_new[niwango_sleep..-1].sum - @t_new[0]
else
  puts @t_new[niwango_sleep..-1].sum
end