#include <bits/stdc++.h>
#define ll long long
#define mod 1000000009
#define inf 40000000007
#define eps 1e-8
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.8lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;
#define M 400002
#define T 500001
int l[M],r[M];
int main()
{
    ios;
    int n;
    cin>>n;
    set<pii>s1,s2,s3,s4;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i]>>r[i];
        s1.insert(mp(r[i],i));
        s2.insert(mp(-l[i],i));
    }
    s3=s1;s4=s2;
    ll ans=0;
    int cur=0;
    


    int ind1=s1.begin()->SS;
    ll dist1=min(abs(cur-l[ind1]),abs(cur-r[ind1]));
    s1.erase(s1.begin());
    s2.erase(mp(-l[ind1],ind1));
    
    if(cur>=l[ind1]&&cur<=r[ind1]){cur=0;}
    else 
    {
        if(abs(cur-l[ind1])<=abs(cur-r[ind1])){cur=l[ind1];}
        else cur=r[ind1];
        ans+=dist1;
    }
    for(int i=2;i<=n;i++)
    {
      //  cout<<cur<<" "<<ans<<endl;
        if(i%2==0)
        {
            ind1=s2.begin()->SS;
            s2.erase(s2.begin());
            s1.erase(mp(r[ind1],ind1));
            if(cur>=l[ind1]&&cur<=r[ind1])continue;
            ll dist1=min(abs(cur-l[ind1]),abs(cur-r[ind1]));
            ans+=dist1;
            if(abs(cur-l[ind1])<=abs(cur-r[ind1]))cur=l[ind1];
            else cur=r[ind1];
        }
        else
        {
            ind1=s1.begin()->SS;
            s1.erase(s1.begin());
            s2.erase(mp(-l[ind1],ind1));
            if(cur>=l[ind1]&&cur<=r[ind1])continue;
            ll dist1=min(abs(cur-l[ind1]),abs(cur-r[ind1]));
            ans+=dist1;
            if(abs(cur-l[ind1])<=abs(cur-r[ind1]))cur=l[ind1];
            else cur=r[ind1];

        }
    }
    ans+=abs(cur);
   // cout<<ans<<endl;
    ll ans1=0;
    cur=0;
    s1=s3;s2=s4;


    ind1=s2.begin()->SS;
    dist1=min(abs(cur-l[ind1]),abs(cur-r[ind1]));
    s2.erase(s2.begin());
    s1.erase(mp(r[ind1],ind1));
    if(cur>=l[ind1]&&cur<=r[ind1]){cur=0;}
    else 
    {
        if(abs(cur-l[ind1])<=abs(cur-r[ind1])){cur=l[ind1];}
        else cur=r[ind1];
        ans1+=dist1;
    }
    for(int i=2;i<=n;i++)
    {
      //  cout<<cur<<" "<<ans1<<endl;
        if(i%2==1)
        {
            ind1=s2.begin()->SS;
            s2.erase(s2.begin());
            s1.erase(mp(r[ind1],ind1));
            if(cur>=l[ind1]&&cur<=r[ind1])continue;
            ll dist1=min(abs(cur-l[ind1]),abs(cur-r[ind1]));
            ans1+=dist1;
            if(abs(cur-l[ind1])<=abs(cur-r[ind1]))cur=l[ind1];
            else cur=r[ind1];
        }
        else
        {
            ind1=s1.begin()->SS;
            s1.erase(s1.begin());
            s2.erase(mp(-l[ind1],ind1));
            if(cur>=l[ind1]&&cur<=r[ind1])continue;
            ll dist1=min(abs(cur-l[ind1]),abs(cur-r[ind1]));
            ans1+=dist1;
            if(abs(cur-l[ind1])<=abs(cur-r[ind1]))cur=l[ind1];
            else cur=r[ind1];

        }
    }
    ans1+=abs(cur);
  //  cout<<ans1<<" "<<cur<<endl;
    cout<<max(ans,ans1)<<endl;
   
}





Measured memory_bytes: 19840