// 2009ツアツジツアツ地ツ凝ヲツ予ツ選 C : Swimming Jam
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		vector<int> t(n), c(n);
		for(int i=0;i<n;i++) cin >> t[i] >> c[i];
		for(int i=0;i<n;i++) c[i] *= 2;
		int ans = 0, count = 0;
		vector<int> lest = t;
		vector<bool> start(n,true);
		while(count != n){
			vector<int> nlest(n);
			vector<bool> nstart(n);
			for(int i=0;i<n;i++){
				if(c[i] == 0) continue;
				if(start[i]){
					int slow = t[i];
					for(int j=0;j<n;j++){
						if(c[j]!=0&&c[i]%2==c[j]%2&&!start[j])
							slow = max(slow, lest[j]);						
					}
					nlest[i] = slow - 1;
					nstart[i] = false;
				} else {
					nlest[i] = lest[i] - 1;
				}
				if(nlest[i] == 0){
					nstart[i] = true;
					c[i]--;
					if(c[i]==0) count++;
				}				
			}
			lest = nlest;
			start = nstart;
			ans++;
		}
		cout << ans << endl;
	}
}