MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
m=gi
dc=m.times.map{gsmi}

cnt=0
q=[]
dc.each do |d,c|
  num=d
  while c>1 do
    if c.odd?
      q<<num
    end
    c/=2
    num*=2
    cnt+=c
    if num>=10
      s=num/10+num%10
      cnt+=c
      num=s
    end
  end
  q<<num
end

q1=q.shift
while q.size>0 do
  q2=q.shift
  num=q1+q2
  cnt+=1
  if num>=10
    s=num/10+num%10
    cnt+=1
    q1=s
  else
    q1=num
  end
end

puts cnt