#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <deque>
using namespace std;

struct S {
	int now, t, rem;
};
bool comp(const S& s1, const S& s2) {
	return s1.t < s2.t;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	while(cin >> n, n) {
		deque<S> lane[2];
		for(int i = 0; i < n; i++) {
			int t, c;
			cin >> t >> c;
			S s = { 0, t, c };
			lane[0].push_back(s);
		}
		sort(lane[0].begin(), lane[0].end(), comp);

		int ans = 0;
		while(lane[0].size() + lane[1].size()) {
			int idx = 0;
			if(lane[0].size() == 0 || lane[1].size() && lane[0][0].t - lane[0][0].now > lane[1][0].t - lane[1][0].now)
				idx = 1;

			int time = lane[idx][0].t - lane[idx][0].now;
			deque<S> temp;
			while(lane[idx].size() && lane[idx][0].t - lane[idx][0].now <= time) {
				S s = lane[idx][0];
				lane[idx].pop_front();

				s.now = 0;
				if(idx == 1) {
					s.rem--;
				}
				if(s.rem) {
					temp.push_back(s);
				}
			}

			sort(temp.begin(), temp.end(), comp);
			for(int i = 0; i < 2; i++) {
				for(S& s : lane[i]) {
					s.now += time;
				}
			}

			for(S s : temp) {
				lane[1 - idx].push_back(s);
			}
			ans += time;
		}
		cout << ans << endl;
	}
}