#include <bits/stdc++.h>
using namespace std;
long long n,top,a[100005],b[100005],cur,dp[100005];
int main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
cin >> n;
for (long long i = 1; i <= n; i++) {
cin>>a[i]>>b[i];
}
memset(dp,100,sizeof(dp));
dp[0]=0;
for (long long i = 1; i <= n; i++) {
long long maxx = b[i];
for (long long j = i - 1; j >= 0; j--) {
if (dp[j]<a[i]) {
dp[i]=min(dp[i],a[i]+maxx*2);
} else {
dp[i]=min(dp[i],dp[j]+maxx*2);
}
maxx=max(maxx,b[j]);
}
}
cout<<dp[n];
return 0;
}