#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 1e18 + 10 : 1e9 + 10;
long long dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
signed main() {
  long long n;
  while (cin >> n, n) {
    vector<vector<long long> > in(n, vector<long long>(2));
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < 2; j++) cin >> in[i][j];
    sort(in.begin(), in.end());
    long long tim = 0;
    queue<pair<long long, long long> > que[2];
    for (long long i = 0; i < n; i++) que[0].push({in[i][0], i});
    while (!que[0].empty() || !que[1].empty()) {
      tim = inf;
      for (long long i = 0; i < 2; i++)
        if (!que[i].empty()) {
          long long t = que[i].front().first;
          if (tim > t) tim = t;
        }
      for (long long i = 0; i < 2; i++) {
        vector<pair<long long, long long> > ne;
        while (!que[i].empty() && que[i].front().first <= tim) {
          ne.push_back(que[i].front());
          que[i].pop();
        }
        for (long long j = 0; j < ne.size(); j++)
          for (long long k = 0; k < ne.size(); k++)
            if (in[j][0] < in[k][0]) swap(ne[j], ne[k]);
        for (long long j = 0; j < ne.size(); j++) {
          pair<long long, long long> p = ne[j];
          if (i) {
            in[p.second][1]--;
            if (in[p.second][1])
              que[i ^ 1].push({tim + in[p.second][0], p.second});
          } else
            que[i ^ 1].push({tim + in[p.second][0], p.second});
        }
      }
    }
    cout << tim << endl;
  }
}
