/*
   Author: ChinmayKarnik
   Time: 14:35:46
   Date: 05-04-2021
*/

#include<bits/stdc++.h>

using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef enum {BLACK,WHITE,GRAY} color;

#define int long long 
#define TESTCASES false
#define FASTIO true
const int maxN = 200009;
const int inf  = (int)1e18 + 1;
int N;
pair<int,int> a[maxN];

int seg1[4*maxN];
int seg2[4*maxN];

void update(int seg[],int v,int tl,int tr,int p,int x)
{
    if(p> tr || p<tl)return;

    if(tl==tr)
    {
        seg[v]=x;
        return;
    }
    int m = (tl+tr)/2;
    update(seg,2*v,tl,m,p,x);
    update(seg,2*v+1,m+1,tr,p,x);
    seg[v]=min(seg[2*v],seg[2*v+1]);
}

int query(int seg[],int v,int tl, int tr,int l,int r)
{
    if(l> tr || tl>r)return inf;

    if(tl>=l && tr<=r)
    {
        return seg[v];
    }
    int m =(tl+tr)/2;
    return min(query(seg,2*v,tl,m,l,r),query(seg,2*v+1,m+1,tr,l,r));
}


void solve()
{
    int i,j,k;
    cin >> N;
   
    int fin = 0;
    for(i=1;i<=N;i++)
    {
        cin >> a[i].first >> a[i].second;
        fin+=a[i].second;
    }
    
    sort(a+1,a+N+1);
    for(i=0;i<4*maxN;i++)
    {
        seg1[i]=seg2[i]=inf;
    }

    update(seg1,1,1,N,N,0);
    update(seg2,1,1,N,N,a[N].first);

    for(i=N-1;i>=1;i--)
    {
        int lo =i+1;
        int hi = N;
        int llo = lo;
        int hhi = hi;

        int cc = a[i].first+a[i].second;

        int mm;
        if(a[lo].first>cc)
        {
            mm=lo-1;
        }
        else if(a[hi].first<=cc)
        {
            mm=hi;
        }
        else{
            while(lo<hi)
            {
                int mid =(lo+hi+1)/2;
                if(a[mid].first<=cc)
                {
                    lo=mid;
                }
                else hi=mid-1;
            }
            mm=lo;
        }
        int ans = inf;

        if(mm>=llo)
        {
            int mq = query(seg1,1,1,N,llo,mm);
            ans = min(ans,mq);
        }
        if(mm+1<=hhi)
        {
             int mq = query(seg2,1,1,N,mm+1,hhi);
             mq-=(a[i].first+a[i].second);
             ans=min(ans,mq);

        }
        update(seg1,1,1,N,i,ans);
        update(seg2,1,1,N,i,ans+a[i].first);

    }

    fin+=query(seg1,1,1,N,1,1);
    cout << fin << "\n";



    
}


signed main()
{
    if(FASTIO)
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    }
    int T = 1;

    if(TESTCASES)
    {
        cin >> T;
    }
    int i,j,k;


    while(T--)
    {
        solve();
    }
}