n = gets.to_i
s = []
t = []
for i in 0...n do
  s[i], t[i] = gets.split
  t[i] = t[i].to_i
end
x = gets.chomp
flag = false
sum = 0
for i in 0...n do
  sum += t[i] if flag
  if s[i] == x
    flag = true
  end
end
puts sum
