#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
}q[10001];
bool cmp(node a,node b)
{
return a.y-b.y;
}
int main()
{
int i,j,n,m;
while(scanf("%d",&m),m)
{
for(i=0;i<m;i++)
scanf("%d%d",&q[i].x,&q[i].y);
sort(q,q+m,cmp);
int max=0;
int w=0;
for(i=0;i<m;i++)
{
w+=q[i].x;
int t=w+q[i].y;
if(t>max)
max=t;
}
printf("%d\n",max);
}
return 0;
}