line = readlines
len = line.length
i = 0
l = 0

while i < len
    line[i] = line[i].chomp.split(' ')
    i += 1
end

i = 1

while line[i][0] != line[line.length - 1][0]
  i += 1
end

i += 1

while i < line.length - 1
  l += line[i][1].to_i
  i += 1
end

puts l