#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;

int n,t[55],c[55];

int main(){
  while(cin>>n,n){
    vector<P>v;
    r(i,n)cin>>t[i]>>c[i];
    r(i,n)v.push_back(P(t[i],i));
    sort(v.begin(),v.end());
    queue<P2>q[2];
    r(i,n)q[0].push(P2(v[i].fi,P(v[i].se,c[v[i].se])));
    int cur=0,ans=0;
    while(q[0].size()+q[1].size()){
      vector<P2>v;
      if(q[cur].empty())cur^=1;
      else if(q[cur^1].size()&&q[cur].front().fi>q[cur^1].front().fi)cur^=1;
      int nxt=q[cur].front().fi;
      while(!q[cur].empty()&&q[cur].front().fi<=nxt){
        v.push_back(q[cur].front());
        v[v.size()-1].fi=nxt+t[v[v.size()-1].se.fi];
        q[cur].pop();
      }
      sort(v.begin(),v.end());
      r(i,v.size()){
        if(cur==1)v[i].se.se--;
        if(v[i].se.se==0)ans=nxt;
        else q[cur^1].push(v[i]);
      }
    }
    cout<<ans<<endl;
  }
}
