# frozen_string_literal: true

m = gets.to_i
dc = m.times.map { gets.split.map(&:to_i) }
d = []
dc.each do |e|
  e[1].times do
    d.push e[0]
  end
end

count = 0
sum = 0
loop do
  e = d.pop
  break if e.nil?

  sum += e
  count += 1
  if sum > 9
    d.push sum % 10
    d.push sum / 10
    sum = 0
    count -= 1
  end
end

puts count - 1
