#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<int> vi;

int main(){
  int n;
  while(cin >> n,n){
    vp s(n);
    rep(i,n)cin >> s[i].first >> s[i].second;
    sort(all(s));

    vi t(n), lap(n);
    rep(i,n){
      t[i] = s[i].first;
      lap[i] = s[i].second;
    }
    vi q1,q2;
    rep(i,n)q1.push_back(i);
    
    int ans = 0;
    while(q1.size() || q2.size()){
      int nxt = 1000;
      vi goal1, goal2;
      if(q1.size())nxt = min(nxt, t[q1.front()]);
      if(q2.size())nxt = min(nxt, t[q2.front()]);
      ans += nxt;
      
      rep(i,q1.size()){
	t[q1[i]] -= nxt;
	if(i>0 && t[q1[i-1]] > t[q1[i]])t[q1[i]] = t[q1[i-1]];
      }
      rep(i,q1.size()){
	if(t[q1[i]]==0){
	  goal1.push_back(q1[i]);
	  q1.erase(q1.begin()+i--);
	}
      }

      rep(i,q2.size()){
	t[q2[i]] -= nxt;
	if(i>0 && t[q2[i-1]] > t[q2[i]])t[q2[i]] = t[q2[i-1]];
      }
      rep(i,q2.size()){
	if(t[q2[i]]==0){
	  goal2.push_back(q2[i]);
	  q2.erase(q2.begin()+i--);
	}
      }
      
      sort(all(goal1)); sort(all(goal2));
      rep(i,goal1.size()){
	q2.push_back(goal1[i]);
	t[goal1[i]] = s[goal1[i]].first;
      }
      rep(i,goal2.size()){
	if(--lap[goal2[i]]){
	  q1.push_back(goal2[i]);
	  t[goal2[i]] = s[goal2[i]].first;
	}
      }
    }
    cout << ans << endl;
  }
}