#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef pair<P,P> Edge;
typedef long long ll;

const double PI=4*atan(1.0);

void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

//#define RED_FILE

#ifdef RED_FILE
ifstream ifs("input.txt");
ofstream ofs("output.txt");
#define cin ifs
#define cout ofs
#endif

int n;
struct info{
	int t,c;
};
info infos[1001];

int main(){
	while(cin>>n&&n!=0){
		vector<pair<int,int> > forward;
		vector<pair<int,int> > back;
		vector<pair<int,int> > tmp;
		for(int i=0;i<n;i++){
			int t,c;
			cin>>t>>c;
			infos[i].t=t;
			infos[i].c=c*2;
			tmp.push_back(make_pair(t,i));
			// »ÝÌoßbÆÔði[
		}
		sort(tmp.begin(),tmp.end());
		// tª¬³¢ÔÉ\[gµÄ¨­
		for(int i = 0; i < n; i++){
			forward.push_back(make_pair(0,tmp[i].second));
		}
		int res=0;
		while(forward.size()!=0||back.size()!=0){
			// forwardÆbackÅAÌCxgª¢ûðÀs(¯ÈçÇ¿çàÀs)
			const int INF=1000000000;
			int fet=INF;
			int bet=INF;
			if(forward.size()!=0){
				int idx=forward[0].second;
				// forwardÅàÁÆàæªÌvfª·é
				fet=abs(infos[idx].t-forward[0].first);
			}
			if(back.size()!=0){
				int idx=back[0].second;
				//backÅàÁÆàæªÌvfª·é
				bet=abs(infos[idx].t-back[0].first);
			}
			int tm=min(fet,bet);
			res+=tm;
			// tmª¾¯SÌÔðißÄ¨­
			for(int i = 0; i < forward.size(); i++)
				forward[i].first+=tm;
			for(int i = 0; i < back.size(); i++)
				back[i].first+=tm;
			// forwardÌÙ¤ª¢
			vector<pair<int,int> > nf;
			vector<pair<int,int> > nb;
			// ðð½·vfðæª©çæè¢Ä¢­
			while(forward.size()){
				int idx=forward[0].second;
				// ðð½·
				if(forward[0].first>=infos[idx].t){
					nf.push_back(make_pair(infos[idx].t,idx));
					infos[idx].c--;
					forward.erase(forward.begin());
				}
				else
					break;
			}
			while(back.size()){
				int idx=back[0].second;
				// ðð½·
				if(back[0].first>=infos[idx].t){
					if(infos[idx].c!=1)
						nb.push_back(make_pair(infos[idx].t,idx));
					infos[idx].c--;
					back.erase(back.begin());
				}
				else
					break;
			}
			// ðð½µ½àÌð\[gµAi[
			sort(nf.begin(),nf.end());
			sort(nb.begin(),nb.end());
			for(int i = 0; i < nf.size(); i++)
				back.push_back(make_pair(0,nf[i].second));
			for(int i = 0; i < nb.size(); i++)
				forward.push_back(make_pair(0,nb[i].second));
		}
		cout<<res<<endl;
	}

	return 0;
}