#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;
typedef pair<int, int> pii;
struct Swimmer {
	int t, c, e;
	Swimmer(int t, int c, int e) : t(t), c(c), e(e) { }
};
const int INF = 1000000000;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<pii> input(n);
		for(int i = 0; i < n; ++i){
			cin >> input[i].first >> input[i].second;
		}
		queue<Swimmer> forward, backward;
		sort(input.begin(), input.end());
		for(int i = 0; i < n; ++i){
			int t = input[i].first, c = input[i].second;
			forward.push(Swimmer(t, c, t));
		}
		int answer = 0;
		while(!forward.empty() || !backward.empty()){
			int ft = (forward.empty() ? INF : forward.front().e);
			int bt = (backward.empty() ? INF : backward.front().e);
			int tm = min(ft, bt);
			answer = tm;
			queue<Swimmer> &q = (ft < bt) ? forward : backward;
			vector<pii> next;
			while(!q.empty() && q.front().e <= tm){
				Swimmer sw = q.front();
				q.pop();
				if(ft >= bt && --sw.c == 0){ continue; }
				next.push_back(pii(sw.t, sw.c));
			}
			sort(next.begin(), next.end());
			queue<Swimmer> &opp = (ft < bt) ? backward : forward;
			for(int i = 0; i < next.size(); ++i){
				int t = next[i].first, c = next[i].second;
				opp.push(Swimmer(t, c, t + tm));
			}
		}
		cout << answer << endl;
	}
	return 0;
}