#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>
struct Record {
	int id, reach_time, speed;
	Record turn(const int time) const { return { id, time + speed, speed }; }
};
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) return 0;
		std::vector<int> time(n); std::vector<int> target(n);
		for (auto i = 0; i < n; ++i) std::cin >> time[i] >> target[i];
		std::queue<Record> forward, backward;
		auto compare_by_speed = [](const Record& a, const Record& b) {return a.speed > b.speed; };
		std::priority_queue<Record, std::vector<Record>, decltype(compare_by_speed)> queue(compare_by_speed);
		for (auto i = 0; i < n; ++i) {
			queue.push(Record{ i, time[i], time[i] });
		}
		for (auto i = 0; i < n; ++i) {
			forward.push(queue.top()); queue.pop();
		}
		auto last_time = 0; auto end_count = 0;
		while (end_count != n) {
			while (!forward.empty() && (backward.empty() || backward.front().reach_time >= forward.front().reach_time)) {
				last_time = forward.front().reach_time;
				while (!forward.empty() && forward.front().reach_time <= last_time) {
					queue.push(forward.front()); forward.pop();
				}
				while (!queue.empty()) {
					backward.push(queue.top().turn(last_time)); queue.pop();
				}
			}
			while (!backward.empty() && (forward.empty() || forward.front().reach_time >= backward.front().reach_time)) {
				last_time = backward.front().reach_time;
				while (!backward.empty() && backward.front().reach_time <= last_time) {
					--target[backward.front().id];
					if (target[backward.front().id] != 0) {
						queue.push(backward.front());
					}
					else {
						++end_count;
					}
					backward.pop();
				}
				while (!queue.empty()) {
					forward.push(queue.top().turn(last_time)); queue.pop();
				}
			}
		}
		std::cout << last_time << std::endl;
	}
}
