#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, t[55], c[55];
  pii s[55];
  while(scanf("%d",&n),n){
    rep(i,n)scanf("%d%d",&s[i].first,&s[i].second);
    sort(s,s+n);
    rep(i,n){
      t[i] = s[i].first;
      c[i] = s[i].second;
    }
    
    vi q[2];
    rep(i,n)q[0].push_back(i);
     
    int ans = 0;
    while(q[0].size() || q[1].size()){
      vi g[2];
      int nxt = 1000;
      rep(x,2){
	if(q[x].size())nxt = min(nxt, t[q[x].front()]);
      }
      ans += nxt;

      rep(x,2){
	rep(i,q[x].size()){
	  t[q[x][i]] -= nxt;
	  if(i>0 && t[q[x][i-1]] > t[q[x][i]])t[q[x][i]] = t[q[x][i-1]];
	}
	while(q[x].size()){
	  if(t[q[x][0]])break;
	  g[x].push_back(q[x][0]);
	  q[x].erase(q[x].begin());
	}
      }
       
      sort(all(g[0])); sort(all(g[1]));
      for(int id : g[0]){
	q[1].push_back(id);
	t[id] = s[id].first;
      }
      for(int id : g[1]){
	if(--c[id]){
	  q[0].push_back(id);
	  t[id] = s[id].first;
	}
      }
    }
    cout << ans << endl;
  }
}