#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;

using namespace std;

#define rep(i,n) for(auto i=0*(n);i<(n);++i)

int main(){
    while(true){
        ll n;
        cin >> n;
        if(n==0) break;
        
        vector<ll> t(n), c(n);
        rep(i, n){
            cin >> t[i] >> c[i];
        }
        
        using P = tuple<ll,ll,ll,ll>;
        priority_queue<P, vector<P>, greater<P> > q;
        ll btm[2] = { 0, 0 };
        
        rep(i, n) {
            q.push(P(t[i], t[i], i, 1ll));
            btm[0] = max(btm[0], t[i]);
        }
        
        while(!q.empty()){
            ll tm, speed, id, turn;
            tie(tm, speed, id, turn) = q.top(); q.pop();
            ll ntm = max(tm + speed, btm[turn%2]);
            btm[turn%2] = max(btm[turn%2], ntm);
            if(turn+1 == c[id]*2) continue;
            q.push(P(ntm, speed, id, turn+1));
        }
        
        cout << max(btm[0], btm[1]) << endl;
    }
    return 0;
}