// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod7=1000000007LL;
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add(LL _x, LL _y, LL _mod=mod7){
  _x+=_y;
  return _x>=_mod ? _x-_mod : _x;
}
inline LL sub(LL _x, LL _y, LL _mod=mod7){
  _x-=_y;
  return _x<0 ? _x+_mod : _x;
}
inline LL mul(LL _x, LL _y ,LL _mod=mod7){
  _x*=_y;
  return _x>=_mod ? _x%_mod : _x;
}
LL mypow(LL _a, LL _x, LL _mod){
  if(_x == 0) return 1LL;
  LL _ret = mypow(mul(_a, _a, _mod), _x>>1, _mod);
  if(_x & 1) _ret=mul(_ret, _a, _mod);
  return _ret;
}
LL mymul(LL _a, LL _x, LL _mod){
  if(_x == 0) return 0LL;
  LL _ret = mymul(add(_a, _a, _mod), _x>>1, _mod);
  if(_x & 1) _ret=add(_ret, _a, _mod);
  return _ret;
}
void sleep(double sec = 1021){
  clock_t s = clock();
  while(clock() - s < CLOCKS_PER_SEC * sec);
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
const int N=101010;
LL n, l[N], r[N];
set< pair<LL,int> > sl, sr;
void init(){
  n=getint();
  for(int i=0; i<n; i++){
    l[i]=getint();
    r[i]=getint();
    sl.insert({l[i], i});
    sr.insert({r[i], i});
  }
}
LL cost(LL cur, int to){
  if(l[to] <= cur and cur <= r[to]) return 0;
  if(r[to] <= cur) return cur-r[to];
  return l[to]-cur;
}
void go(LL& cur, int to){
  sl.erase({l[to], to});
  sr.erase({r[to], to});
  if(l[to] <= cur and cur <= r[to])
    return;
  if(r[to] <= cur) cur=r[to];
  else cur=l[to];
}
bool gt[N];
LL cal1(){
  vector< pair<LL,int> > vr, vl;
  for(int i=0; i<n; i++){
    vl.push_back({l[i], i});
    vr.push_back({r[i], i});
  }
  sort(vl.begin(), vl.end());
  sort(vr.begin(), vr.end());
  reverse(vr.begin(), vr.end());
  for(int i=0; i<n; i++)
    gt[i]=false;
  LL cur=0, ans=0;
  for(int i=0; i<n; i++){
    if(i & 1){
      while(true){
        int to=vl.back().second;
        vl.pop_back();
        if(gt[to]) continue;
        ans+=cost(cur, to);
        go(cur, to);
        gt[to]=true;
        break;
      }
    }else{
      while(true){
        int to=vr.back().second;
        vr.pop_back();
        if(gt[to]) continue;
        ans+=cost(cur, to);
        go(cur, to);
        gt[to]=true;
        break;
      }
    }
  }
  ans+=abs(cur);
  return ans;
}
LL cal2(){
  vector< pair<LL,int> > vr, vl;
  for(int i=0; i<n; i++){
    vl.push_back({l[i], i});
    vr.push_back({r[i], i});
  }
  sort(vl.begin(), vl.end());
  sort(vr.begin(), vr.end());
  reverse(vr.begin(), vr.end());
  for(int i=0; i<n; i++)
    gt[i]=false;
  LL cur=0, ans=0;
  for(int i=0; i<n; i++){
    if((i & 1) == 0){
      while(true){
        int to=vl.back().second;
        vl.pop_back();
        if(gt[to]) continue;
        ans+=cost(cur, to);
        go(cur, to);
        gt[to]=true;
        break;
      }
    }else{
      while(true){
        int to=vr.back().second;
        vr.pop_back();
        if(gt[to]) continue;
        ans+=cost(cur, to);
        go(cur, to);
        gt[to]=true;
        break;
      }
    }
  }
  ans+=abs(cur);
  return ans;
}
void solve(){
  LL xans=max(cal1(), cal2());
  LL cur=0, ans=0;
  while(sl.size()){
    int candl=sl.rbegin()->second;
    int candr=sr.begin()->second;
    LL tol=cost(cur, candl);
    LL tor=cost(cur, candr);
    if(tol > tor){
      ans+=tol;
      go(cur, candl);
    }else{
      ans+=tor;
      go(cur, candr);
    }
  }
  ans+=abs(cur);
  ans=max(ans, xans);
  cout<<ans<<endl;
}
int main(){
  build();
  //__ = getint();
  while(__ --){
    init();
    solve();
  }
}


Measured memory_bytes: 19600