#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("a.in", "r", stdin);
auto OUT = freopen("a.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 5e3 + 5;
int n = mread(), t[N], a[N], f[N];
signed main(){
for(int i = 1; i <= n; i ++){
cin >> t[i] >> a[i];
}
memset(f, 0x3f, sizeof(f));
f[0] = 0;
for(int i = 1; i <= n; i ++){
int ma = a[i];
for(int j = i - 1; j >= 0; j --){
int tmp = max(f[j], t[i]);
f[i] = min(f[i], tmp + ma + ma);
ma = max(ma, a[j]);
}
}
printf("%lld", f[n]);
return 0;
}