#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>

using namespace std;

struct Swimer {
  int time;
  int end;
  int lap;
  int lane;
  Swimer(int time, int end, int lap, int lane) :
    time(time), end(end), lap(lap), lane(lane) {;}
  bool operator<(const Swimer &rhs) const {
    if (end != rhs.end) { return end > rhs.end; }
    return time > rhs.time;
  }
};

int n;
int block[2];

int main() {
  while (scanf("%d", &n), n) {
    int ans = 0;
    memset(block, 0, sizeof(block));
    priority_queue<Swimer> que;
    for (int i = 0; i < n; i++) {
      int t, c;
      scanf("%d %d", &t, &c);
      que.push(Swimer(t, 0, c, 0));
    }
    while (!que.empty()) {
      Swimer swimer = que.top();
      que.pop();
      ans = max(ans, swimer.end);
      if (swimer.lap == 0) { continue; }
      //cout << swimer.time << " " << swimer.end << " " << swimer.lap << " " << swimer.lane << endl;
      int nend = swimer.end + swimer.time;
      if (block[swimer.lane] > nend) {
        nend = block[swimer.lane];
      } else {
        block[swimer.lane] = nend;
      }
      int nlane = (swimer.lane + 1) & 1;
      int nlap = swimer.lap;
      if (nlane == 0) { nlap--; }
      que.push(Swimer(swimer.time, nend, nlap, nlane));
    }
    printf("%d\n", ans);
  }
}