#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef complex<ld> Point;
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

struct intr {
	int a, b;
	intr() {
		a = b = 1;
	}
	intr(int x) {
		a = x; b = 1;
	}
	intr(int x, int y) {
		a = x; b = y;
	}
	bool operator<(const intr &r)const {
		return a * r.b < b*r.a;
	}
	bool operator!=(const intr &r)const {
		return a * r.b != b * r.a;
	}
};
int cnt[50];
int t[50],c[50];
typedef pair<intr, int> speP;
bool comp(int i, int j) {
	return t[i] < t[j];
}
bool comp2(speP x, speP y) {
	if (x.first != y.first)return x.first < y.first;
	return t[x.second] < t[y.second];
}
void solve() {
	int n;
	while (cin >> n, n) {
		fill(cnt, cnt + n, 0);
		rep(i, n) {
			cin >> t[i] >> c[i];
		}
		vector<speP> lane[2],coplane[2];
		vector<int> fin[2],cop[2];
		rep(i, n) {
			fin[0].push_back(i);
		}
		int num = n; int tmp = 0;
		while (num) {
			tmp++;
			rep(j, 2) {
				cop[j].clear(); coplane[j].clear();
			}
			rep(j, 2) {
				intr ma(1,1);
				sort(lane[j].begin(), lane[j].end(),comp2);
				per(i, lane[j].size()) {
					speP p = lane[j][i];
					int id = p.second;
					intr r = p.first;
					r.a++;
					if (ma < r) {
						r = ma;
					}
					if (r.a == r.b) {
						if (j == 1) {
							cnt[id]++;
							if (cnt[id] == c[id]) {
								num--; continue;
							}
						}
						cop[j ^ 1].push_back(id);
					}
					else {
						coplane[j].push_back({ r,id });
					}
					ma = r;
				}
				sort(fin[j].begin(), fin[j].end(), comp);
				rep(i, fin[j].size()) {
					int id = fin[j][i];
					intr r(1, t[id]);
					if (ma < r)r = ma;
					if (r.a == r.b) {
						if (j == 1) {
							cnt[id]++;
							if (cnt[id] == c[id]) {
								num--; continue;
							}
						}
						cop[j ^ 1].push_back(id);
					}
					else {
						coplane[j].push_back({ r,id });
					}
				}
			}
			rep(j, 2)fin[j] = cop[j];
			rep(j, 2)lane[j] = coplane[j];
		}
		cout << tmp << endl;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}

