import sys

read = sys.stdin.read



M = int(eval(input()))

dc = list(map(int, read().split()))

dig_sum = 0

dig = 0

for d, c in zip(*[iter(dc)] * 2):

    dig_sum += d * c

    dig += c



answer = (dig_sum - 1) // 9 + dig - 1

print(answer)
import sys

read = sys.stdin.read



M = int(eval(input()))

dc = list(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)
import sys

read = sys.stdin.read
M = int(eval(input()))
dc = list(map(int, read().split()))
dig_sum = 0
dig = 0
for d, c in zip(*[iter(dc)] * 2):
    dig_sum += d * c
    dig += c
answer = (dig_sum - 1) // 9 + dig - 1
print(answer)

import sys

read = sys.stdin.read
M = int(eval(input()))
dc = list(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)

-dig_sum = 0 -dig = 0 +dig = [0] * 10 +cnt = 0 +answer = 0 -    dig_sum += d * c -    dig += c -answer = (dig_sum - 1) // 9 + dig - 1 +    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)