#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t[55], c[55];
  pair<int, int> s[55];
  while (scanf("%d", &n), n) {
    for (int i = 0; i < (int)(n); i++) scanf("%d%d", &s[i].first, &s[i].second);
    sort(s, s + n);
    for (int i = 0; i < (int)(n); i++) {
      t[i] = s[i].first;
      c[i] = s[i].second;
    }
    vector<int> q[2];
    for (int i = 0; i < (int)(n); i++) q[0].push_back(i);
    int ans = 0;
    while (q[0].size() || q[1].size()) {
      vector<int> g[2];
      int nxt = 1000;
      for (int x = 0; x < (int)(2); x++) {
        if (q[x].size()) nxt = min(nxt, t[q[x][0]]);
      }
      ans += nxt;
      for (int x = 0; x < (int)(2); x++) {
        for (int i = 0; i < (int)(q[x].size()); i++) {
          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((g[0]).begin(), (g[0]).end());
      sort((g[1]).begin(), (g[1]).end());
      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;
  }
}
