You are given the number of programmers, N, participating in the preliminary stage of DDCC 20XX. At most 9 contestants can advance to the finals due to venue constraints. The preliminary stage consists of multiple rounds. The number of contestants advancing to the next round is determined by choosing two consecutive digits in the decimal notation of the current number of contestants and replacing them with their sum. The preliminary stage ends when 9 or fewer contestants remain. The goal is to find the maximum possible number of rounds in the preliminary stage. The input consists of M, followed by sequences of digits and their counts. The output should be the maximum possible number of rounds. The constraints are given for M, the digits, and their counts. Sample inputs and outputs are provided for illustration.

# Buggy version:
n=int(input())

dnum =0
dsum =0

for i in range(n):
  d,c=map(int,input().split())
  dnum += c
  dsum += d*c
  
ans = c-1 + dsum//9

print(ans)

# Fixed version:
n=int(input())

dnum =0
dsum =0

for i in range(n):
  d,c=map(int,input().split())
  dnum += c
  dsum += d*c
  
ans = dnum-1 + (dsum-1)//9

print(ans)

# Buggy version:
M = int(input())
Keta=0
Sum=0

for _ in range(M):
    d,c = map(int,input().split())
    Keta+=c
    Sum=d*c
print(Keta-1 + (Sum-1)//9)


# Fixed version:
M = int(input())
Keta=0
Sum=0

for _ in range(M):
    d,c = map(int,input().split())
    Keta+=c
    Sum+=d*c
print(Keta-1 + (Sum-1)//9)

# Buggy version:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d

import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    def aint(x):
        ret=0
        cnt=0
        while(x>0):
            cnt+=1
            ret+=x//10
            x//=10
        cnt-=1
        return int(ret)-cnt
            
    if n>=10:
        ans+=aint(n)
        
    print(ans,n)
    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=aint(n)-1
        print(ans,n)
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()


# Fixed version:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d

import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    def aint(x):
        ret=0
        cnt=0
        while(x>0):
            cnt+=1
            ret+=x//10
            x//=10
        cnt-=1
        return int(ret)-cnt
            
    if n>=10:
        ans+=aint(n)
        

    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=aint(n)
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()

# Buggy version:
import sys
sys.stdin.readline

def main():
    m = int(input())
    a = [list(map(int, input().split())) for _ in range(m)]
    wa = 0
    length = 0
    for i,j in a:
        wa += i*j
        length += j
    print(wa,length)
    print(length-1+(wa-1)//9)
    
    
if __name__=="__main__":
    main()


# Fixed version:
import sys
sys.stdin.readline

def main():
    m = int(input())
    a = [list(map(int, input().split())) for _ in range(m)]
    wa = 0
    length = 0
    for i,j in a:
        wa += i*j
        length += j
    #print(wa,length)
    print(length-1+(wa-1)//9)
    
    
if __name__=="__main__":
    main()

# Buggy version:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M=I()
    dig=0
    S=0
    for i in range(M):
        d,c=MI()
        dig+=d
        S+=d*c

    print(dig-1+(S)//10)

main()



# Fixed version:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M=I()
    dig=0
    S=0
    for i in range(M):
        d,c=MI()
        dig+=c
        S+=d*c

    print(dig-1+(S-1)//9)

main()

# Buggy version:
import sys
input = sys.stdin.readline
m = int(input())
ans = 0
sum_num = 0
c_sum = 0
for i in range(m):
    d,c = map(int, input().split())
    sum_num += d*c
    c_sum += c
#合計に対して、9減らす行為が何回出来るか
print(d-1 + (c_sum//9))

# Fixed version:
import sys
input = sys.stdin.readline
m = int(input())
ans = 0
sum_num = 0
c_sum = 0
for i in range(m):
    d,c = map(int, input().split())
    sum_num += d*c
    c_sum += c
#合計に対して、9減らす行為が何回出来るか
print(c_sum-1 + ((sum_num-1)//9))

# Buggy version:
n=int(input())
sums=0
digits=0
for _ in range(n):
  a,b=map(int,input().split())
  sums+=a*b
  digits+=b
ans=(digits-1)+(sums+9-1)//9
print(ans)

# Fixed version:
n=int(input())
sums=0
digits=0
for _ in range(n):
  a,b=map(int,input().split())
  sums+=a*b
  digits+=b
ans=(digits-1)+(sums-1)//9
print(ans)

# Buggy version:
m = int(input())
CD = [list(map(input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(c * d, 9)
  count += q
  tmp += m
  if tmp >= 9:
    count += 1
    tmp %= 9
  total += d
print(total - 1 + count)

# Fixed version:
m = int(input())
CD = [list(map(int, input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(tmp + c * d, 9)
  count += q
  tmp = m
  total += d
print(total - 1 + count)

# Buggy version:
m = int(input())
csum = 0
dsum = 0
for i in range(m):
  d,c = (int(x) for x in input().split())
  csum += c
  dsum += d*c
print(c-1 + dsum // 9)

# Fixed version:
m = int(input())
csum = 0
dsum = 0
for i in range(m):
  d,c = (int(x) for x in input().split())
  csum += c
  dsum += d*c
print(csum-1 + (dsum-1) // 9)

# Buggy version:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    m = II()
    Digit = 0
    Sum = 0
    for _ in range(m):
        d, c = LI()
        Digit += c
        Sum += d * c
    print(Digit + Sum // 9)
    return


#main
if __name__ == '__main__':
    solve()


# Fixed version:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    m = II()
    Digit = 0
    Sum = 0
    for _ in range(m):
        d, c = LI()
        Digit += c
        Sum += d * c
    print(Digit + (Sum - 1) // 9 - 1)
    return


#main
if __name__ == '__main__':
    solve()

# Buggy version:
m = int(input())
tot = 0
ans = 0
for i in range(m):
    x, y = map(int, input().split())
    tot += x * y
    ans += y
while tot >= 10:
    tot = tot // 10 + tot % 10
    ans += tot
print(ans - 1)

# Fixed version:
m = int(input())
tot = 0
ans = 0
for i in range(m):
    x, y = map(int, input().split())
    tot += x * y
    ans += y
while tot >= 10:
    ans += tot // 10
    tot = tot // 10 + tot % 10
print(ans - 1)

# Buggy version:
m=int(input())
d=[]
c=[]
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
ans=0
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        i5=0
        for i in range(len(s)):
            s[i]=int(s[i])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>=10:
                #ret+=1
                g+=2
            else:
                g+=1
        z=sum(s)
        ret+=z//10-1
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)[0]+len(ka)-1)


# Fixed version:
m=int(input())
d=[]
c=[]
z=0
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
    z+=a*b
ans=0
print(sum(c)-1+(z-1)//9)
exit()
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        i5=0
        for i in range(len(s)):
            s[i]=int(s[i])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>=10:
                #ret+=1
                g+=2
            else:
                g+=1
        z=sum(s)
        ret+=(z-10)//10
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)[0]+len(ka)-1)

# Buggy version:
x=0;y=0
for _ in range(int(input())):
  d,c=map(int,input().split())
  x+=d*c
  y+=c
print(y-2+x//9)

# Fixed version:
x=0;y=0
for _ in range(int(input())):
  d,c=map(int,input().split())
  x+=d*c
  y+=c
print(y-1+(x-1)//9)

# Buggy version:
m=int(input())
ans=m-1
tmp=0
for i in range(m):
    q,r=map(int,input().split())
    tmp+=q*r

ans+=(tmp-1)//9
print(ans)
    


# Fixed version:
m=int(input())
ans=0
tmp=0
dig=0
for i in range(m):
    q,r=map(int,input().split())
    tmp+=q*r
    dig+=r

ans+=(tmp-1)//9
print(ans+dig-1)

# Buggy version:
n = int(input())
d, c = 0, 0

for i in range(n):
    p, q = map(int, input().split())
    d = d + p
    c = c + p*q

print((d-1)+(c-1)//9)

# Fixed version:
n = int(input())
d, c = 0, 0

for i in range(n):
    p, q = map(int, input().split())
    d = d + q
    c = c + p*q

print((d-1)+(c-1)//9)

# Buggy version:
import sys

def answer():
    input = sys.stdin.readline
    M = int(input())

    Ds = [0] * M
    Cs = [0] * M
    total = 0

    for i in range(M):
        d, c = map(int, input().split())
        Ds[i] = d
        Cs[i] = c
        total += d * c

    digits = sum(Ds)

    ans = (digits-1) + (total-1) // 9

    print(ans)


if __name__ == '__main__':
    answer()


# Fixed version:
import sys

def answer():
    input = sys.stdin.readline
    M = int(input())

    Ds = [0] * M
    Cs = [0] * M
    total = 0

    for i in range(M):
        c, d = map(int, input().split())
        Cs[i] = c
        Ds[i] = d
        total += d * c

    digits = sum(Ds)

    ans = (digits-1) + (total-1) // 9

    print(ans)


if __name__ == '__main__':
    answer()

# Buggy version:
M = int(input())
d = [0] * M
c = [0] * M
for i in range(M):
	d[i], c[i] = map(int, input().split())
D = 0
S = 0
for i in range(M):
	D += c[i]
	S += d[i] * c[i]
print((D - 1) + (S // 9)


# Fixed version:
M = int(input())
D = 0
S = 0
for i in range(M):
    c,d = map(int,input().split())
    D += d
    S += c*d
print(D-1+(S-1)//9)

# Buggy version:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

print(trans)

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += x
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    if a + b >= 10:
        answer += 2
        last.append((a + b) // 10 + (a + b) % 10)
    else:
        answer += 1
        last.append(a + b)

print(answer)

# Fixed version:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += q * 2
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    c = a + b
    if c >= 10:
        answer += 2
        last.append(c // 10 + c % 10)
    else:
        answer += 1
        last.append(c)

print(answer)

# Buggy version:
M = int(input())
S = 0
res = -1
for _ in range(M):
    d, c = map(int, input().split())
    res += d
    S += c

res += S // 9
print(res)

# Fixed version:
M = int(input())
S = -1
res = -1
for _ in range(M):
    d, c = map(int, input().split())
    res += c
    S += d*c

res += S // 9
print(res)

# Buggy version:
m = int(input())
count = 0
sum1 = 0
for i in range(m):
    d,c = map(int,input().split())
    sum1 += d*c
    count += c
if (sum1%9 == 0) print(sum1//9 - 1 + count - 1)
else print(sum1//9 + count -1)


# Fixed version:
m = int(input())
count = 0
sum1 = 0
for i in range(m):
    d,c = map(int,input().split())
    sum1 += d*c
    count += c
if (sum1%9 == 0):
    print(sum1//9 - 1 + count - 1)
else:
    print(sum1//9 + count - 1)

# Buggy version:
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c
  if s>=10:
    t = s//10
    ans+=t
    s-= t*10

print(ans)

# Fixed version:
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c
  if s>=10:
    t = (s-1)//9
    ans+=t
    s-= t*9

ans -= 1
print(ans)

# Buggy version:
m = int(input())
d = [0] * m
c = [0] * m
for i in range(m):
    d[i], c[i] = map(int, input().split())

print((sum(c)-1+sum([c[i]*d[i] for i in range(m)]-1)//9) % 1000000007)

# Fixed version:
m=int(input())
d=[0]*m
c=[0]*m
for i in range(m):
  d[i],c[i]=map(int,input().split())
a=0
for i in range(m):
  a=a+d[i]*c[i]
print(sum(c)-1+(a-1)//9)

# Buggy version:
M = int(input())

lis = [0] * 10
able =0

for i in range(M):

    d,c = map(int,input().split())

    lis[d] = c

    able += d * c
    
print ( sum(lis) + (able-1) // 9 )


# Fixed version:
M = int(input())

lis = [0] * 10
able =0

for i in range(M):

    d,c = map(int,input().split())

    lis[d] += c

    able += d * c
    
print ( sum(lis)-1 + (able-1) // 9 )

# Buggy version:
m = int(input())
L = []
for _ in range(m):
    L.append(list(map(int, input().split())))

short = []
additional = 0
for elm in L:
    additional += (elm[1] - 1)
    total = elm[0] * elm[1]
    additional += (total - 1) // 9
    if total > 9:
        res = total % 9
    else:
        res = total
    short.append(res)

prev = 0
additional += len(short) - 1
for elm in short:
    prev = prev + elm
    if prev > 9:
        prev -= 9
        additional += 1

print(additional)
    

# Fixed version:
m = int(input())
L = []
for _ in range(m):
    L.append(list(map(int, input().split())))

short = []
additional = 0
for elm in L:
    additional += (elm[1] - 1)
    total = elm[0] * elm[1]
    if total > 9:
        if total % 9 == 0:
            additional += (total // 9) - 1
        else:
            additional += total // 9
        # additional += (total - 1) // 9
    if total > 9:
        if total % 9 == 0:
            res = 9
        else:
            res = total % 9
    else:
        res = total
    short.append(res)

prev = 0
additional += len(short) - 1
for elm in short:
    prev = prev + elm
    if prev > 9:
        prev -= 9
        additional += 1

print(additional)

# Buggy version:
m=int(input())
s,c=0,0
for i in range(m):
  d,c=map(int,input().split())
  s+=d*c
  k+=c
print(k-1+(s-1)//9)

# Fixed version:
m = int(input())
s = 0
ans = -1
for i in range(m):
  d,c = map(int,input().split())
  s += d*c
  ans += c

print(ans + (s-1)//9)

# Buggy version:
m=int(input())
l=[list(map(int,input().split())) for i in range(m)]
ct=0;sum=0
for i in range(m):
  ct+=l[i][0]*l[i][1]
  sum+=l[i][1]
print(sum-1+(ct//9)-1)

# Fixed version:
m=int(input())
l=[list(map(int,input().split())) for i in range(m)]
ct=0;sum=0
for i in range(m):
  ct+=l[i][0]*l[i][1]
  sum+=l[i][1]
print(sum-1+((ct-1)//9))

# Buggy version:
N=int(input())
d=[];c=[]
for i in range(N):
    di,ci=map(int,input().split())
    d.append(di);c.append(ci)
# print(d) #DB
# print(c) #DB
s=sum([d[i]*c[i] for i in range(N)])
# print(s) #DB
t=0
while s>10:
    s=s//10+s%10
    t+=s

ans=sum(c)-1+t
print(ans)

# Fixed version:
N=int(input())
d=[];c=[]
for i in range(N):
    di,ci=map(int,input().split())
    d.append(di);c.append(ci)
# print(d) #DB
# print(c) #DB
s=sum([d[i]*c[i] for i in range(N)])
# print(s) #DB
t=0
while s>=10:
    t+=s//10
    s=s//10+s%10

ans=sum(c)-1+t
print(ans)

# Buggy version:
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-1)//9)
else:
    print(keta-1)
'''

# Fixed version:
M = int(input())
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-1)//9)
else:
    print(keta-1)

# Buggy version:
# coding: utf-8
# Your code here!

m= int(input())
dc=[]
s=0
for i in range(m):
    dc.append(list(map(int,input().split())))
    s+=dc[i][0]*dc[i][1]

print(s)

ans=s//9

for i in range(m):
    ans+=dc[i][1]

if s%9==0:
    ans-=1

print(ans-1)


# Fixed version:
# coding: utf-8
# Your code here!

m= int(input())
dc=[]
s=0
for i in range(m):
    dc.append(list(map(int,input().split())))
    s+=dc[i][0]*dc[i][1]


ans=s//9

for i in range(m):
    ans+=dc[i][1]

if s%9==0:
    ans-=1

print(ans-1)

# Buggy version:
n = int(input())
ans = -1
num = 0
for i in range(n):
    a,b = map(int,input().split())
    ans += b
    num += a * b
    if num > 9:
        ans += (num-9) // 9
        num %= 9
        if num == 0:
            num = 9
print(ans,num)

# Fixed version:
n = int(input())
ans = -1
num = 0
for i in range(n):
    a,b = map(int,input().split())
    ans += b
    num += a * b
    if num > 9:
        ans += num // 9
        num %= 9
        if num == 0:
            ans -= 1
            num = 9
print(ans)