#include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<stack>
#include<set>
#include<algorithm>
using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define DBG 0
const int INF = 1e9;
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		vector<int> t(n), c(n);
		rep(i, 0, n) {
			cin >> t[i] >> c[i];
		}

		set<pair<int, int>> S1, S2;

		{  // init
			rep(i, 0, n) {
				S1.insert({t[i], i});
			}
		}

		int ans = 0;
		while (S1.size() || S2.size()) {
			if (DBG) {
				cout << "S1.size() = " << S1.size() << ", S2.size() = " << S2.size() << endl;
			}

			set<tuple<int, int, bool>> next;
			int a = INF, b = INF;
			if (not S1.empty())a = S1.begin()->first;
			if (not S2.empty())b = S2.begin()->first;
			int T = min(a,b);
			while (!S1.empty()) {
				int x, idx;
				tie(x, idx) = *S1.begin();
				if (x != T) break;
				next.insert(make_tuple(T + t[idx], idx, false));
				S1.erase(S1.begin());
			}
			while (!S2.empty()) {
				int x, idx;
				tie(x, idx) = *S2.begin();
				if (x != T) break;
				next.insert(make_tuple(T + t[idx], idx, true));
				S2.erase(S2.begin());
			}

			for (auto& tpl : next) {
				int nt, idx;
				bool f;
				tie(nt, idx, f) = tpl;
				if (f) {
					// into S1
					if (!S1.empty()) {
						auto itr = S1.rbegin();
						nt = max(nt, get<0>(*itr));
					}

					// decrease c
					c[idx]--;
					if (DBG) {
						cout << "! c ";

						rep(i, 0, n) {
							cout << c[i] << (i == n - 1 ? '\n' : ' ');
						}
					}
					if (c[idx] > 0) {
						S1.insert({ nt, idx });
					}
					else {
						ans = max(ans, nt - t[idx]);  // !!
					}
				}
				else {
					// into S2
					if (!S2.empty()) {
						auto itr = S2.rbegin();
						nt = max(nt, get<0>(*itr));
					}
					S2.insert({ nt, idx });
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}
