#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
using namespace rel_ops;
struct rat{
	int a,b;
	rat(int a,int b) :a(a),b(b){}
};
inline int gcd(int x,int y){
	if(y==0) return abs(x);
	return gcd(y,x%y);
}
inline rat normz(rat x){
	int g=gcd(x.a,x.b);
	// if(x.b<0) x.a*=-1,x.b*=-1;
	return rat(x.a/g,x.b/g);
}
inline rat operator+(const rat& x,const rat& y){
	return normz(rat(x.a*y.b+x.b*y.a,x.b*y.b));
}
inline bool operator<(const rat& x,const rat& y){
	return x.a*y.b<x.b*y.a;
}
inline bool operator==(const rat& x,const rat& y){
	return x.a*y.b==x.b*y.a;
}

typedef vector<int> Vi;
int main(){
	while(true){
		int N,t[50],c[50];
		cin>>N;
		if(N==0) break;
		rep(i,N) cin>>t[i]>>c[i];
		map<rat,Vi> mp;	//pos->id
		Vi fst;
		rep(i,N) fst.pb(i);
		mp[rat(0,1)]=fst;
		rep(tm,150000){
			map<rat,Vi> nmp;
			rat mn(2,1);
			for(auto it=mp.rbegin();it!=mp.rend();it++){
				bool slow=1;
				rat r=it->fs;
				Vi vc=it->sc;
				if(r==rat(0,1)||r==rat(1,1)) slow=0;
				if(slow){
					int mxt=0;
					for(int v:vc) chmax(mxt,t[v]);
					rat nr=min(r+rat(1,mxt),mn);
					chmin(mn,nr);
					nmp[nr].insert(nmp[nr].end(),vc.begin(),vc.end());
				}else{
					for(int v:vc){
						rat nr=min(r+rat(1,t[v]),mn);
						nmp[nr].pb(v);
					}
				}
			}
			for(int v:nmp[rat(2,1)]){
				c[v]--;
				if(c[v]) nmp[rat(0,1)].pb(v);
			}
			nmp.erase(rat(2,1));
			mp=nmp;
			if(mp.empty()){
				cout<<tm+1<<endl;
				break;
			}
		}
	}
}