import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto C = new int[](N);
    auto D = new long[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!long);
        C[i] = s[0].to!int;
        D[i] = s[1];
    }

    long ans = 0;
    int tmp = 0;
    int[] amari;

    foreach (i; 0..N) {
        if (D[i] <= 1) {
            continue;
        }
        tmp = 0;
        while (D[i] > 1) {
            ans += D[i] / 2;
            if (D[i] % 2) {
                amari ~= C[i];
            }
            if (D[i] > 1) {
                if (C[i] >= 5) {
                    ans += D[i] / 2;
                    C[i] = C[i] * 2 - 9;
                } else {
                    C[i] *= 2;
                }
            }
            if (D[i] > 1) {
                tmp = C[i];
            }
            D[i] /= 2;
        }
        foreach (a; amari) {
            if (tmp + a >= 10) {
                ans += 2;
                tmp = (tmp + a) - 9;
            } else {
                ans += 1;
                tmp += a;
            }
        }
        amari = [];
        C[i] = tmp;
    }

    tmp = C.front;
    foreach (a; C[1..$]) {
        if (tmp + a >= 10) {
            ans += 2;
            tmp = (tmp + a) - 9;
        } else {
            ans += 1;
            tmp += a;
        }
    }

    ans.writeln;
}


