#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Data
{
public:
    int t, c, tRest;
    Data(){}
    Data(int t0, int c0){
        t = tRest = t0;
        c = c0;
    }
    bool operator<(const Data& d) const{
        return t < d.t;
    }
};

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Data> d(n);
        for(int i=0; i<n; ++i){
            int t, c;
            cin >> t >> c;
            d[i] = Data(t, c);
        }
        sort(d.begin(), d.end());

        deque<Data> lane1, lane2;
        for(int i=0; i<n; ++i)
            lane1.push_back(d[i]);

        int ret = 0;
        while(!lane1.empty() || !lane2.empty()){
            ++ ret;
            for(unsigned i=0; i<lane1.size(); ++i)
                -- lane1[i].tRest;
            for(unsigned i=0; i<lane2.size(); ++i)
                -- lane2[i].tRest;
            if(lane1.size() > 0 && lane1[0].tRest == 0){
                vector<Data> d;
                while(!lane1.empty() && lane1[0].tRest <= 0){
                    lane1[0].tRest = lane1[0].t;
                    d.push_back(lane1[0]);
                    lane1.pop_front();
                }
                sort(d.begin(), d.end());
                for(unsigned i=0; i<d.size(); ++i)
                    lane2.push_back(d[i]);
            }
            if(lane2.size() > 0 && lane2[0].tRest == 0){
                vector<Data> d;
                while(!lane2.empty() && lane2[0].tRest <= 0){
                    -- lane2[0].c;
                    if(lane2[0].c > 0){
                        lane2[0].tRest = lane2[0].t;
                        d.push_back(lane2[0]);
                    }
                    lane2.pop_front();
                }
                sort(d.begin(), d.end());
                for(unsigned i=0; i<d.size(); ++i)
                    lane1.push_back(d[i]);
            }
        }

        cout << ret << endl;
    }
}