import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    int[] T, C;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        T = new int[N];
        C = new int[N];
        foreach (i; 0 .. N) {
            scanf("%d %d\n", &T[i], &C[i]);
        }
        return true;
    }
    struct Swimmer {
        int time;
        int C;
    }
    struct S {
        int time;
        int which;
        Swimmer s;
    }
    void solve() {
        BinaryHeap!(Array!S, (x, y) => (x.time == y.time ? x.s.time > y.s.time : x.time > y.time)) PQ;
        foreach (i; 0 .. N) {
            PQ.insert(S(0, 0, Swimmer(T[i], C[i])));
        }
        int time0, time1;
        while (!PQ.empty) {
            S event = PQ.front; PQ.removeFront;
            //writeln(event);
            if (event.which == 0) {
                int ntime = max(time0, event.time + event.s.time);
                time0 = ntime;
                PQ.insert(S(ntime, 1, event.s));
            } else {
                int ntime = max(time1, event.time + event.s.time);
                time1 = ntime;
                event.s.C--;
                if (event.s.C == 0) continue;
                PQ.insert(S(ntime, 0, event.s));
            }
        }
        writeln(time1);
    }
    while (input) solve;
}