#include<iostream>
#include<vector>
#include<algorithm>
#include <cmath>
using namespace std;



struct S {
  int c;
  int r;
  double v;
  double x;
  double prex;
  bool operator < (const S &s) const {
    if(v != s.v) return v < s.v;
    return false;
  }
};

const double eps = 1e-5;
const int MAX_N = 54;
const double inf = 1e100;
int N;
vector<S> v;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

void input(){
  v.clear();
  for(int i = 0; i < N; i++){
    S s;
    int t, c;
    cin >> t >> c;
    s.c = c;
    s.r = 0;
    s.v = 1.0/(double)t;
    s.x = 0;
    s.prex = 0;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
}

bool check() {
  for(int i = 0; i < v.size(); ++i) {
    if(v[i].c != 0) return false;
  }
  return true;
}

void next(int res) {
  for(int i = 0; i < v.size(); ++i) {
    if(v[i].c == 0) continue;
    v[i].prex = v[i].x;
    double begin = v[i].x;
    v[i].x += v[i].v;
    double end = v[i].x;
    for(int j = 0; j < i; ++j) {
      if(v[j].c == 0) continue;
      if(v[i].r != v[j].r) continue;
      if(equals(v[i].prex, 0.0) && equals(v[j].prex, 0.0)) continue;
      if(!equals(v[j].prex, v[i].prex) && v[j].prex < v[i].prex) {
	continue;
      }
      if(!equals(begin,v[j].x) && begin < v[j].x && v[j].x < end) {
	v[i].x = min(v[i].x, v[j].x);
	//cout << res << ":" << v[i].x << endl;
      }
    }
    v[i].x = min(v[i].x, 1.0);
    if(equals(1.0, v[i].x)) {
      v[i].x = 0;
      if(v[i].r == 1) {
	--v[i].c;
      }
      v[i].r = 1 - v[i].r;
    }
  }
}

void solve(){
  input();
  int res;
  for(res = 0 ; ; res++){
    /*
    cout << res << endl;
    for(int i = 0; i < v.size(); ++i) {
      cout << i << ": remain lap=" << v[i].c << ", x=" << v[i].r+v[i].x << endl;
    }
    cout << endl;
    */
    if(check()) break;
    next(res);
  }
  cout << res << endl;
}

int main(){
  while(cin >> N && N){
    solve();
  }
  return 0;
}