
#include "bits/stdc++.h"
using namespace std;



int main() {
	while (1) {
		int n; cin >> n;
		if (!n)break;
		vector<pair<int, int>>mers;
		for (int i = 0; i < n; ++i) {
			int t, c; cin >> t >> c;
			c *= 2;
			mers.push_back(make_pair(t, c));
		}
		sort(mers.begin(), mers.end(), [](const pair<int, int>&l, const pair<int, int>&r) {return l.first < r.first; });

		vector<pair<int, int>>sits;//f:終了時間　s:残りレーン数
		vector<int>lanetime(2);
		for (int i = 0; i < n; ++i) {
			sits.push_back(make_pair(mers[i].first, mers[i].second));
			lanetime[0] = mers[i].first;
		}
		lanetime[1] = 0;
		int swimming = n;
		int time = 1;
		for (time = 1; swimming;++time){
			for (int i = 0; i < n; ++i) {
				if (sits[i].second == 0) {
					continue;
				}else if (sits[i].first == time) {
					sits[i].second--;
					if (sits[i].second == 0) {
						swimming--;
						continue;
					}
					else {
						sits[i].first = max(time + mers[i].first, lanetime[sits[i].second % 2]);
						lanetime[sits[i].second % 2] = sits[i].first;
					}
				}
			}
		}
		cout << time - 1 << endl;
	}
	return 0;
}