#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

int Time[64], Lap[64], Ans;

struct Event {
	int TimeStamp, who, where;
	Event() {}
	Event(int t, int who, int where) :
		TimeStamp(t), who(who), where(where) {}
	inline bool operator< (const Event& comp) const {
		if(TimeStamp != comp.TimeStamp) return TimeStamp > comp.TimeStamp;
		if(where != comp.where) return where > comp.where;
		if(Time[who] != Time[comp.who]) return Time[who] > Time[comp.who];
		return who > comp.who;
	}
};

priority_queue<Event> Q;
int n, Arrive[2];

template<class T> inline bool _max(T& data, const T& update) {
	if(data < update) {
		data = update;
		return true;
	}
	return false;
}

int main(void) {
	while(scanf("%d", &n), n) {
		register int i;
		Ans = 0;
		Arrive[0] = Arrive[1] = 0;
		for(i = 0; i < n; ++ i) scanf("%d%d", Time + i, Lap + i);
		for(i = 0; i < n; ++ i) Q.push(Event(Time[i], i, 1)), _max(Arrive[1], Time[i]);
		while(Q.size()) {
			const Event &ev = Q.top();
			int nextSide = !ev.where, nextTime = max(Arrive[nextSide], ev.TimeStamp + Time[ev.who]);
			_max(Arrive[nextSide], nextTime); _max(Ans, nextTime);
			if (!nextSide) -- Lap[ev.who];
			if (Lap[ev.who] > 0) {
				Q.push(Event(nextTime, ev.who, nextSide));
			}
			Q.pop();
		}
		printf("%d\n", Ans);
	}
}