#include <bits/stdc++.h>
using namespace std;
class C {
 public:
  int time, cnt, now;
  C() { now = 0; }
  bool operator<(const C &second) const { return time < second.time; }
};
bool isEnd(vector<pair<int, C> > &v) {
  for (int i = 0; i < v.size(); ++i)
    if (v[i].second.cnt != 0) return false;
  return true;
}
int main() {
  int n;
  while (cin >> n && n) {
    vector<pair<int, C> > v(n);
    for (int i = 0; i < n; ++i) {
      cin >> v[i].second.time >> v[i].second.cnt;
      v[i].first = v[i].second.time;
    }
    sort(v.begin(), v.end());
    int ans = 0;
    while (!isEnd(v)) {
      if (v[0].second.cnt == 0) continue;
      ans += v[0].first;
      for (int i = 1; i < v.size(); ++i)
        if (v[i].second.cnt != 0) v[i].first -= v[0].first;
      int next = (v[0].second.now + 1) % 2;
      v[0].first = v[0].second.time;
      for (int i = 1; i < v.size(); ++i) {
        if (v[i].second.cnt == 0 || v[i].second.now != next) continue;
        v[0].first = max(v[0].first, v[i].first);
      }
      v[0].second.now = next;
      if (next == 0) v[0].second.cnt -= 1;
      sort(v.begin(), v.end());
    }
    cout << ans << endl;
  }
  return 0;
}
