#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
struct A{
	int nowa,nowb,speed,rap;
};
int main()
{
	while(cin>>N,N)
	{
		vector<A>P;
		for(int i=0;i<N;i++)
		{
			A a;
			cin>>a.speed>>a.rap;
			a.nowa=0;
			a.nowb=a.speed;
			P.push_back(a);
		}
		sort(P.begin(),P.end(),[](A a,A b){return a.speed<b.speed;});
		int ans=0;
		while(!P.empty())
		{
			vector<A>Q;
			P[0].nowa++;
			for(int i=1;i<P.size();i++)
			{
				P[i].nowa++;
				if(P[i].nowa*P[i-1].nowb>P[i-1].nowa*P[i].nowb)
				{
					P[i].nowa=P[i-1].nowa;
					P[i].nowb=P[i-1].nowb;
				}
			}
			for(int i=0;i<P.size();i++)
			{
				if(P[i].nowa==P[i].nowb)
				{
					P[i].nowa=P[i].nowb=P[i].speed;
				}
				else if(P[i].nowa==P[i].nowb*2)
				{
					P[i].nowa=0;
					P[i].nowb=P[i].speed;
					P[i].rap--;
				}
			}
			for(int i=0;i<P.size();i++)
			{
				if(P[i].rap>0)Q.push_back(P[i]);
			}
			stable_sort(Q.begin(),Q.end(),[](A a,A b){
				return a.nowa*b.nowb!=b.nowa*a.nowb?a.nowa*b.nowb>b.nowa*a.nowb:
					a.nowa%a.nowb==0?a.speed<b.speed:false;
			});
			P=Q;
			ans++;
		}
		cout<<ans<<endl;
	}
}

