#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-a;i>=a;i--)
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
const int mod=1e9+7;
const int maxn=5e4+10;
struct node{
int x,y;
node(int _x=0,int _y=0):x(_x),y(_y){};
}p[maxn];
bool cmp(node& A,node& B){
return A.x+max(A.y,B.x)+B.y<B.x+max(B.y,A.x)+A.y;
}
/*
先把题解粘上,过一段时间在看
2台机器的情况下有多项式算法(Johnson算法):
https://www.cnblogs.com/yijiesuifeng/p/3790656.html
https://blog.csdn.net/ncepuzhuang/article/details/8924202
3台或以上的机器是NP-hard算法(非常难):
https://blog.csdn.net/bitcarmanlee/article/details/51935400
*/
int main(){
int n;
scanf("%d",&n);
rep(i,0,n){
scanf("%d %d",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp);
//rep(i,0,n) printf("i:%d (%d,%d)\n",i,p[i].x,p[i].y);
int ans=p[0].x+p[0].y,m=p[0].x;
rep(i,1,n){
m+=p[i].x;
ans=max(ans,m)+p[i].y;
}
printf("%d\n",ans);
return 0;
}