n = gets.to_i
ss = []
tt = []

n.times{
	s, t = gets.split
	ss << s
	tt << t.to_i
}

x = gets.chomp

index = ss.index(x)

result = tt[(index + 1) .. -1].inject(:+)

if result == nil then
	puts 0
else
	puts result
end
