#include<bits/stdc++.h>
using namespace std;

struct Swimmer{
    int idx,t,c;
    int reach;
};
const int INF=1e9;
bool operator<(Swimmer lhs,Swimmer rhs){
    return lhs.t<rhs.t;
}
int solve(int n){
    vector<Swimmer> swimmer(n);
    for(int i=0;i<n;i++){
        int t,c;
        cin>>t>>c;
        swimmer[i]=Swimmer{i,t,c,t};
    }
    sort(swimmer.begin(),swimmer.end());
    queue<Swimmer> fque;
    queue<Swimmer> bque;
    for(auto &s:swimmer) fque.push(s);

    int res=0;
    while(!(fque.empty() && bque.empty())){
        int ft=(fque.empty() ? INF : fque.front().reach);
        int bt=(bque.empty() ? INF : bque.front().reach);
        if(ft<bt){
            auto s=fque.front();
            int t=s.reach;
            vector<Swimmer> goals;
            while(!fque.empty() && fque.front().reach<=s.reach){
                goals.push_back(fque.front());
                fque.pop();
            }
            sort(goals.begin(),goals.end());
            for(auto &e:goals){
                bque.push(Swimmer{e.idx,e.t,e.c,t+e.t});
            }
            res=t;
        }
        else{
            auto s=bque.front();
            int t=s.reach;
            vector<Swimmer> goals;
            while(!bque.empty() && bque.front().reach<=s.reach){
                goals.push_back(bque.front());
                bque.pop();
            }
            sort(goals.begin(),goals.end());
            for(auto &e:goals){
                if(e.c-1>0) fque.push(Swimmer{e.idx,e.t,e.c-1,t+e.t});
            }
            res=t;
        }
    }
    return res;
}
int main(){
    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}
