#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

void pairsort(int n,int *a,int *b){
	pair<int,int> c[50];
	rep(i,n) c[i]=make_pair(-a[i],b[i]);
	sort(c,c+n);
	rep(i,n) a[i]=-c[i].first, b[i]=c[i].second;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		int pace[50],lap[50];
		rep(i,n) scanf("%d%d",pace+i,lap+i);

		pairsort(n,pace,lap);

		vector<int> stop[50];
		rep(i,n){
			int t=0;
			stop[i].push_back(t);
			rep(j,2*lap[i]){
				int t_next=t+pace[i];
				rep(k,i){
					int idx=lower_bound(stop[k].begin(),stop[k].end(),t)-stop[k].begin()-1;
					if(0<=idx && idx+1<stop[k].size() && idx%2==j%2){
						t_next=max(t_next,stop[k][idx+1]);
					}
				}
				t=t_next;
				stop[i].push_back(t);
			}
		}

		int ans=0;
		rep(i,n) ans=max(ans,stop[i].back());
		printf("%d\n",ans);
	}

	return 0;
}