import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

enum MP = [
    [0,0],
    [9,10],
    [9,11],
    [3,4],
    [9,13],
    [7,11],
    [3,5],
    [9,16],
    [9,17],
    [0,0]
];

void main()
{
    auto M = readln.chomp.to!int;
    long[] ds;
    long r;
    foreach (_; 0..M) {
        auto dc = readln.split.to!(long[]);
        auto d = dc[0];
        auto c = dc[1];
        if (d == 0) {
            r += c-1;
            c = 1;
        } else if (d == 9) {
            r += (c-1)*2;
            c = 1;
        } else {
            void calc(long m, long p) {
                if (c%m == 0) {
                    r += (c/m-1)*p;
                    c = m;
                } else {
                    r += c/m*p;
                    c %= m;
                }
            }
            calc(MP[d][0], MP[d][1]);
        }
        while (c--) ds ~= d;
    }
    while (ds.length > 1) {
        ++r;
        auto c = ds[0]+ds[1];
        if (c >= 10) {
            ds[0] = 1;
            ds[1] = c%10;
        } else {
            ds[1] = c;
            ds = ds[1..$];
        }
    }
    writeln(r);
}