#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int n, c[50], t[50];
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return t[a.first] < t[b.first];
}
int main() {
  while (cin >> n, n) {
    for (int i = 0; i < (int)n; i++) cin >> t[i] >> c[i];
    queue<pair<int, pair<int, int> > > q[2];
    for (int i = 0; i < (int)n; i++)
      q[0].push(make_pair(i, make_pair(t[i], 0)));
    int cur = 0, next = 1, ans;
    while (q[0].size() || q[1].size()) {
      if (q[cur].empty())
        swap(cur, next);
      else if (q[next].size() &&
               q[cur].front().second.first > q[next].front().second.first)
        swap(cur, next);
      vector<pair<int, int> > v;
      int nxt = q[cur].front().second.first;
      while (q[cur].size() && q[cur].front().second.first <= nxt) {
        v.push_back(
            make_pair(q[cur].front().first, q[cur].front().second.second));
        q[cur].pop();
      }
      sort((v).begin(), (v).end(), cmp);
      for (int i = 0; i < (int)v.size(); i++) {
        if (cur == 1) v[i].second++;
        if (v[i].second == c[v[i].first])
          ans = nxt;
        else
          q[next].push(make_pair(v[i].first,
                                 make_pair(nxt + t[v[i].first], v[i].second)));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
