#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

struct Data { int time, lane, lap; };

bool is_end(vector<bool>& v)
{
	for (auto i : v)
	{
		if (!i) return true;
	}
	return false;
}

int main()
{
	int n;
	while (cin >> n, n)
	{
		vi v;
		vector<Data> tmp;
		REP(i, n)
		{
			int t, c; cin >> t >> c;
			v.emplace_back(t);
			tmp.push_back(Data{ t, 0, c });
		}
		vector<bool> finish(n);
		int ans = 0;
		while (is_end(finish))
		{
			int time = INF, p;
			REP(i, n)
			{
				if (finish[i]) continue;
				if (tmp[i].time < time)
				{
					time = tmp[i].time;
					p = i;
				}
			}
			ans += time;
			REP(i, n)
			{
				if (finish[i]) continue;
				if (tmp[i].time != time) tmp[i].time -= time;
				else
				{
					if (tmp[i].lane)
					{
						tmp[i].lap--;
						if (tmp[i].lap == 0) finish[i] = true;
						tmp[i].lane = 0;
					}
					else
					{
						tmp[i].lane = 1;
					}
					tmp[i].time = -1;
				}
			}
			int maxf = 0, maxb = 0;
			REP(i, n)
			{
				if (finish[i]) continue;
				if (tmp[i].time != -1)
				{
					if (tmp[i].lane == 0) chmax(maxf, tmp[i].time);
					else chmax(maxb, tmp[i].time);
				}
			}
			REP(i, n)
			{
				if (finish[i]) continue;
				if (tmp[i].time == -1)
				{
					if (tmp[i].lane == 0) tmp[i].time = max(maxf, v[i]);
					else tmp[i].time = max(maxb, v[i]);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}