Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = map(int, sys.stdin.readline().rstrip().split(" "))

def too_slow(d_pairs):
    ds = []
    for d, c in d_pairs:
        for _ in range(c):
            ds.append(d)
    d, c = 0, 0
    for next_d in ds:
        c += 1
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
    return c-1


def contract_list(ds):
    d, c = 0, -1
    for next_d, next_c in ds:
        c += next_c
        c += 1
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
        # print(d, c)
    return d, c

def contract_pair(d, orig_c):
    c = 0
    ds = [(d, c)]
    for _ in range(int(math.log(orig_c, 2)) + 1):
        d = d + d
        c = c*2 +1
        if d >= 10:
            d = d % 10 + 1
            c += 1
        ds.append((d, c))
    # print(ds)

    ds_for_calc = []
    for i, b in enumerate(reversed(bin(orig_c)[2:])):
        # print(bin(orig_c), b)
        if b == "1":
            ds_for_calc.append(ds[i])
    # print("for_cal", ds_for_calc)

    return contract_list(ds_for_calc)


ds_for_calc = []
orig_ds = []
for _ in range(M):
    d, c = map(int, sys.stdin.readline().rstrip().split(" "))
    orig_ds.append((d, c))
    ds_for_calc.append(contract_pair(d, c))
    # print(ds_for_calc[-1])
# print("last_list", ds_for_calc)
answer = contract_list(ds_for_calc)[1]
# print(too_slow(orig_ds), answer)
# assert too_slow(orig_ds) == answer
print(answer)

exit(0)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = map(int, sys.stdin.readline().rstrip().split(" "))
total_sum = 0
total_digits = 0
for _ in range(M):
    d, c = map(int, sys.stdin.readline().rstrip().split(" "))
    total_digits += c
    total_sum += d*c
answer = ((total_sum-1) // 9) + total_digits -1
print(answer)
exit(0)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = map(int, sys.stdin.readline().rstrip().split(" "))

def too_slow(d_pairs):
    ds = []
    for d, c in d_pairs:
        for _ in range(c):
            ds.append(d)
    d, c = 0, 0
    for next_d in ds:
        c += 1
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
    return c-1


def contract_list(ds):
    d, c = 0, -1
    for next_d, next_c in ds:
        c += next_c
        c += 1
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
        # print(d, c)
    return d, c

def contract_pair(d, orig_c):
    c = 0
    ds = [(d, c)]
    for _ in range(int(math.log(orig_c, 2)) + 1):
        d = d + d
        c = c*2 +1
        if d >= 10:
            d = d % 10 + 1
            c += 1
        ds.append((d, c))
    # print(ds)

    ds_for_calc = []
    for i, b in enumerate(reversed(bin(orig_c)[2:])):
        # print(bin(orig_c), b)
        if b == "1":
            ds_for_calc.append(ds[i])
    # print("for_cal", ds_for_calc)

    return contract_list(ds_for_calc)


ds_for_calc = []
orig_ds = []
for _ in range(M):
    d, c = map(int, sys.stdin.readline().rstrip().split(" "))
    orig_ds.append((d, c))
    ds_for_calc.append(contract_pair(d, c))
    # print(ds_for_calc[-1])
# print("last_list", ds_for_calc)
answer = contract_list(ds_for_calc)[1]
# print(too_slow(orig_ds), answer)
assert too_slow(orig_ds) == answer
print(answer)

exit(0)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = map(int, sys.stdin.readline().rstrip().split(" "))
total_sum = 0
total_digits = 0
for _ in range(M):
    d, c = map(int, sys.stdin.readline().rstrip().split(" "))
    total_digits += c
    total_sum += d*c
answer = ((total_sum-1) // 9) + total_digits -1
print(answer)
exit(0)