#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int solve(int N, vector<int> T, vector<int> C) {
	vector<int> remaining_lap = C;

	vector<pair<int, int>> D[2];
	for (int i = 0; i < N; i++) D[0].push_back(make_pair(i, 0));

	for (int t = 0; t <= 150000; t++) {
		for (int i = 0; i < 2; i++) {
			vector<pair<int, int>> S;
			vector<bool> VV(D[i].size(), false);
			
			for (int j = 0; j < D[i].size(); j++) {
				if (D[i][j].second == t) {
					int pos = D[i][j].first;
					remaining_lap[pos]--; VV[j] = true;
					if (remaining_lap[pos] == 0) continue;
					S.push_back(make_pair(T[pos], pos));
				}
			}
			sort(S.begin(), S.end());
			
			vector<pair<int, int>> new_D;
			for (int j = 0; j < D[i].size(); j++) { if (VV[j] == false) new_D.push_back(D[i][j]); }
			D[i] = new_D;

			for (int j = 0; j < S.size(); j++) {
				int pos = S[j].second;
				D[i ^ 1].push_back(make_pair(pos, t + T[pos]));
			}
		}
		for (int i = 0; i < 2; i++) {
			for (int j = 1; j < D[i].size(); j++) {
				D[i][j].second = max(D[i][j].second, D[i][j - 1].second);
			}
		}

		if (D[0].size() == 0 && D[1].size() == 0) return t;
	}
	return -1;
}

int main() {
	while (true) {
		int N; cin >> N; if (N == 0) break;
		vector<int> T(N, 0), C(N, 0);
		for (int i = 0; i < N; i++) { cin >> T[i] >> C[i]; C[i] *= 2; C[i]++; }

		cout << solve(N, T, C) << endl;
	}
	return 0;
}
