#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
#define F first
#define S second
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, c[50], t[50];
bool cmp(const pi &a, const pi &b){
	return t[a.F] < t[b.F];
}
int main(){
	while(cin >> n, n){
		rep(i, n) cin >> t[i] >> c[i];
		vector<pi> vv;
		rep(i, n) vv.pb(mp(t[i], i));
		sort(all(vv));
		queue<pair<int, pi> > q[2];
		rep(i, n) q[0].push(mp(vv[i].S, mp(vv[i].F, 0)));
		
		int cur = 0, next = 1, ans = 0;
		while(q[0].size() || q[1].size()){
			
			if(q[cur].empty()) swap(cur, next);
			else if(q[next].size() && q[cur].front().S.F > q[next].front().S.F) swap(cur, next);
			
			vector<pi> v;
			int nxt = q[cur].front().S.F;
			while(q[cur].size() && q[cur].front().S.F <= nxt){
				v.pb(mp(q[cur].front().F, q[cur].front().S.S));
				q[cur].pop();
			}
			sort(all(v), cmp);
			rep(i, v.size()){
				if(cur == 1) v[i].S++;
				if(v[i].S == c[v[i].F]) assert(ans <= nxt), ans = nxt;
				else q[next].push(mp(v[i].F, mp(nxt + t[v[i].F], v[i].S)));
			}
		}
		cout << ans << endl;
	}
	return 0;
}