#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
void write(int x){
	if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);
	putchar(x%10+'0');
}
inline void writeln(int x){
	write(x);puts("");
}
const int N=1e5+10;
int n,f[N],s[N];
struct ppap{
	int a,c;
}a[N];
inline bool cmp(ppap a,ppap b){
	return a.a==b.a?a.c<b.c:a.a<b.a;
}
vector<int>e[N],g[N];
multiset<int>ss;
signed main()
{
	n=read();
	int ans=0;
	for(int i=1;i<=n;i++){
		a[i].a=read();a[i].c=read();
		ans+=a[i].c;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)s[i]=a[i].a;
	int minn=1e18;
	memset(f,0x3f,sizeof f);
	for(int i=1;i<=n;i++){
		if(e[i].size()){
			for(int j=0;j<e[i].size();j++){
				int x=e[i][j];ss.erase(ss.find(x));
			}
		}
		if(g[i].size()){
			for(int j=0;j<g[i].size();j++){
				int x=g[i][j];
				minn=min(minn,x);
			}
		}
//		cout<<ss.size()<<endl;
		if(i==1)f[1]=0;
		else{
			if(ss.size())f[i]=*ss.begin();
			f[i]=min(f[i],a[i].a+minn);
		}
		int p=lower_bound(s+1,s+n+1,a[i].a+a[i].c)-s;
//		cout<<p<<endl;
		if(p==i)p++;
		if(p>i+1){
			e[p].push_back(f[i]);
			ss.insert(f[i]);
		}
		g[p].push_back(f[i]-a[i].a-a[i].c);
//		cout<<a[i].a<<' '<<a[i].c<<' '<<i<<' '<<f[i]<<' '<<minn<<endl;
	}
	writeln(ans+f[n]);
	return 0;
}