#include<iostream>
#include<cassert>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define pb         push_back

const double eps  = 1e-10;
const int inf = (1 << 21);

class state{
public:
  int t,now,ori;
  int cnt;
  bool operator<(const state & a)const{
    if (now*a.t != a.now*t)return now*a.t < a.now*t;
    return t > a.t;
  }
};

int solve(int n,vector<state>& in){
  int ans=0;
  sort(ALL(in));
  int m= n;

  while(n){
    int mint = inf;
    rep(i,n){
      mint = min(mint,in[i].t-in[i].now%in[i].t);
    }
    
    rep(i,n){
      in[i].now+=1;
      int tnow=in[i].now-1,tt=in[i].t;
      rep(j,n){
	if (i == j)continue;
	if ((tnow)*in[j].t >=(in[j].now)*tt)continue;
	if (in[i].t <= in[j].t)continue;
	double t = (in[i].t*in[j].t)*(in[j].now-in[i].now)/(double)(in[j].t-in[i].t);
	if (t <0)continue;
	if (t < mint){
	  mint=(int)(t+1);
	}
      }
      in[i].now-=1;
    }
    
    rep(i,n){
      in[i].now+=mint;
      int tnow=in[i].now-mint,tt=in[i].t;
      rep(j,n){
	if (i == j)continue;
	if ((tnow)*in[j].t >=(in[j].now)*tt)continue;
	if ((in[i].now)*in[j].t >= (in[j].now+mint)*in[i].t){
	  in[i].now=in[j].now+mint;
	  in[i].t=in[j].t;
	}
      }
      in[i].now-=mint;
    }

    rep(i,n){
      in[i].now+=mint;
    }

    rep(i,n){
      if (in[i].now%in[i].t == 0){
	if (in[i].now/in[i].t == 1){
	  in[i].t=in[i].ori;
	  in[i].now=in[i].ori;
	}else if (in[i].now/in[i].t==2){
	  in[i].t=in[i].ori;
	  in[i].now=0;
	  in[i].cnt--;
	  if (in[i].cnt == 0)in[i].now=inf,m--;
	}
      }
    }
    
    sort(ALL(in));
    for(int i=n-1;i>=0;i--){
      if (in[i].now == inf)n--;
    }
    ans+=mint;
  }
  return ans;
}

int main(){
  int n;
  while(cin>>n && n){
    vector<state> in;
    rep(i,n){
      int t;
      int lap;
      cin>>t>>lap;
      in.pb((state){t,0,t,lap});
    }
    cout << solve(n,in) << endl;
  }
}