#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct S{
  int time, lap;
  int rem;  
};
bool operator < (S a, S b)
{
  return a.time < b.time;
}

int main(void)
{
  int n;
  while( cin >> n && n ){
    vector<S> lane[2];
    for(int i=0; i<n; ++i){
      S s;
      cin >> s.time >> s.lap;
      s.rem = s.time;
      lane[0].push_back( s );
    }
    sort( lane[0].begin(), lane[0].end() );
    int time = 0;
    while( lane[0].size() | lane[1].size() ){
      
      for(int i=0; i<2; ++i){
	for(int j=0; j<lane[i].size(); ++j){
	  if( j ) lane[i][j].rem = max( lane[i][j].rem-1, lane[i][j-1].rem );
	  else lane[i][j].rem--;
	}
      }

      vector<S> tmp[2];
      for(int i=0; i<2; ++i){
	for(int j=0; j<lane[i].size(); ++j){
	  if( lane[i][j].rem == 0 ){
	    tmp[i].push_back( lane[i][j] );
	    tmp[i].back().rem = tmp[i].back().time;
	    lane[i].erase( lane[i].begin() + j );
	    --j;
	  }
	}
	sort( tmp[i].begin(), tmp[i].end() );
      }
      
      for(int i=0; i<tmp[0].size(); ++i){
	lane[1].push_back( tmp[0][i] );
      }

      for(int i=0; i<tmp[1].size(); ++i){
	if( --tmp[1][i].lap ){
	  lane[0].push_back( tmp[1][i] );
	}
      }
      
      ++time;
    }
    cout << time << endl;
  }
  return 0;
}