#include<bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;

int N;
P swimmer[50];
map<int, vector<P> > lane[2];

int main(){
	while(cin >> N, N){
		lane[0].clear();
		lane[1].clear();

		for(int i = 0; i < N; i++){
			cin >> swimmer[i].first >> swimmer[i].second;
			swimmer[i].second *= 2;
			lane[0][swimmer[i].first].push_back(swimmer[i]);	
		}

		int time = 0;
		while(lane[0].size() > 0 || lane[1].size() > 0){
			int i;
			if(lane[0].size() > 0 && (lane[1].size() == 0 || (*(lane[0].begin())).first < (*(lane[1].begin())).first)){
				i = 0;
			}else{
				i = 1;
			}
			auto h = *(lane[i].begin());
			time = h.first;
			lane[i].erase(h.first);
			sort(h.second.begin(), h.second.end());
			for(auto p : h.second){
				if(p.second > 1){
					p.second--;
					int nt = time + p.first;
					if(lane[(i+1)%2].size() > 0 && (*(lane[(i+1)%2].rbegin())).first >= nt){
						(*(lane[(i+1)%2].rbegin())).second.push_back(p);
					}else{
						lane[(i+1)%2][nt].push_back(p);
					}
				}
			}
		}
		cout << time << endl;
	}
}