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

void main()
{
    auto M = readln.chomp.to!int;
    long r;
    long[] ns;
    foreach (_; 0..M) {
        auto dc = readln.split.to!(long[]);
        auto d = dc[0];
        auto c = dc[1];
        while (c) {
            if (c % 2 == 1) ns ~= d;
            c /= 2;
            switch (d) {
                case 0: r += c; break;
                case 1: r += c; d = 2; break;
                case 2: r += c; d = 4; break;
                case 3: r += c; d = 6; break;
                case 4: r += c; d = 8; break;
                case 5: r += c*2; d = 1; break;
                case 6: r += c*2; d = 3; break;
                case 7: r += c*2; d = 5; break;
                case 8: r += c*2; d = 7; break;
                case 9: r += c*2; d = 9; break;
                default:
            }
        }
    }
    while (ns.length > 1) {
        ++r;
        auto x = ns[$-1] + ns[$-2];
        ns = ns[0..$-2];
        if (x > 9) ns ~= 1;
        ns ~= x%10;
    }
    writeln(r);
}