#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

double func(int n){
	ll res = 0;
	vector<pii> man(n);
	foreach(i, man)cin>>i.first>>i.second;
	sort(all(man));
	vector<pii> p[2];
	int slowest[2]={0, 0};

	//time side needtime needcount
	using T = tuple<int, int, int, int>;
	priority_queuer<T> pq;
	foreach(i, man){
		pq.emplace(i.first, 1, i.first, i.second*2-1);
		chmax(slowest[1], i.first);
	}
	while(pq.size()){
		int ntime = get<0>(pq.top());
		chmax(res, (ll)ntime);
		while(pq.size()&&ntime==get<0>(pq.top())){
			T d = pq.top();
			pq.pop();
			int lane = get<1>(d);
			int needtime = get<2>(d);
			int needcount = get<3>(d);
			if(needcount){
				p[lane].emplace_back(needtime, needcount);
			}
		}
		rep(i, 2){
			sort(all(p[i]));
			foreach(j, p[i]){
				int needtime = max(slowest[!i], ntime+j.first);
				slowest[!i] = needtime;
				pq.emplace(needtime, !i, j.first, j.second-1);
			}
			p[i].clear();
		}
	}

	return res;
}

int main(){
	int n;
	while(cin>>n&&n){
		cout << func(n) << endl;
	}
	return 0;
}

