# Original solution
import sys
sys.setrecursionlimit(10**6)

def read_tokens():
    return input().strip().split(' ')

def read_ints():
    return [int(token) for token in read_tokens()]

n, = read_ints()
c = [0] * n
d = [0] * n

# s = ''
for i in range(n):
    # d[i] = (i + 1) % 10
    # c[i] = 10**15 // n
    d[i], c[i] = read_ints()
    # s += str(d[i]) * c[i]



# print(f's={s}')
# cache = {}
# def f(s):
#     global cache
#     x = int(s)
#     if x <= 9:
#         return 0
#     if s in cache:
#         return cache[s]
#     ans = 0
#     best = ''
#     for i in range(len(s) - 1):
#         a = int(s[i])
#         b = int(s[i+1])
#         t = f(s[:i] + str(a+b) + s[i+2:])
#         ans = max(ans, t + 1)
#         if t + 1 == ans:
#             best = s[:i] + str(a+b) + s[i+2:]

#     for i in range(len(s) - 1):
#         a = int(s[i])
#         b = int(s[i+1])
#         t = f(s[:i] + str(a+b) + s[i+2:])
#         if t + 1 != ans:
#             print(f'!!! {s} {i} {s[:i] + str(a+b) + s[i+2:]} {t + 1} {bedt} {ans}')

#     cache[s] = ans
#     return ans

# print(f(s))

# while True:
#     s, = read_tokens()
#     print(f(s))

def processBlock(n, c):
    if not (c > 0):
        while True:
            pass
    if c == 1:
        return n, 0
    if c % 2 == 0:
        if 2 * n < 10:
            rn, rc = processBlock(2 * n, c // 2)
            return rn, rc + c // 2
        else:
            d = (2 * n) // 10 + (2 * n) % 10
            rn, rc = processBlock(d, c // 2)
            return rn, rc + c
    rn, rc = processBlock(n, c - 1)
    if n + rn < 10:
        return n + rn, rc + 1
    else:
        d = (n + rn) // 10 + (n + rn) % 10
        return d, rc + 2

def solve(D, C):
    ret = 0
    a = []
    for d, c in zip(D, C):
        n, cc = processBlock(d, c)
        ret += cc
        a.append(n)
    while len(a) > 1:
        d1 = a.pop()
        d2 = a.pop()
        ret += 1
        if d1 + d2 < 10:
            a.append(d1 + d2)
        else:
            a.append(1)
            a.append((d1 + d2) % 10)
    return ret

print((solve(d, c)))
# print(f(s))

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

def read_tokens():
    return input().strip().split(' ')

def read_ints():
    return [int(token) for token in read_tokens()]

n, = read_ints()
c = [0] * n
d = [0] * n

# s = ''
for i in range(n):
    # d[i] = (i + 1) % 10
    # c[i] = 10**15 // n
    d[i], c[i] = read_ints()
    if c[i] == 0:
        c[i] = 1/c[i]
    # s += str(d[i]) * c[i]



# print(f's={s}')
# cache = {}
# def f(s):
#     global cache
#     x = int(s)
#     if x <= 9:
#         return 0
#     if s in cache:
#         return cache[s]
#     ans = 0
#     best = ''
#     for i in range(len(s) - 1):
#         a = int(s[i])
#         b = int(s[i+1])
#         t = f(s[:i] + str(a+b) + s[i+2:])
#         ans = max(ans, t + 1)
#         if t + 1 == ans:
#             best = s[:i] + str(a+b) + s[i+2:]

#     for i in range(len(s) - 1):
#         a = int(s[i])
#         b = int(s[i+1])
#         t = f(s[:i] + str(a+b) + s[i+2:])
#         if t + 1 != ans:
#             print(f'!!! {s} {i} {s[:i] + str(a+b) + s[i+2:]} {t + 1} {bedt} {ans}')

#     cache[s] = ans
#     return ans

# print(f(s))

# while True:
#     s, = read_tokens()
#     print(f(s))

def processBlock(n, c):
    if not (c > 0):
        while True:
            pass
    if c == 1:
        return n, 0
    if c % 2 == 0:
        if 2 * n < 10:
            rn, rc = processBlock(2 * n, c // 2)
            return rn, rc + c // 2
        else:
            d = (2 * n) // 10 + (2 * n) % 10
            rn, rc = processBlock(d, c // 2)
            return rn, rc + c

    # c % 2 == 1
    # c != 1

    rn, rc = processBlock(n, c - 1)
    if n + rn < 10:
        return n + rn, rc + 1
    else:
        d = (n + rn) // 10 + (n + rn) % 10
        return d, rc + 2

def solve(D, C):
    ret = 0
    a = []
    for d, c in zip(D, C):
        n, cc = processBlock(d, c)
        ret += cc
        a.append(n)
    while len(a) > 1:
        d1 = a.pop()
        d2 = a.pop()
        ret += 1
        if d1 + d2 < 10:
            a.append(d1 + d2)
        else:
            a.append(1)
            a.append((d1 + d2) % 10)
    return ret

print((solve(d, c)))
# print(f(s))