#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,r,c;
    cin>>n;
    vector<int> vr;
    vector<int> vc;
    vector<int> rv;
    vector<int> cv;
    vector<int> rm;
    vector<int> cm;
    for(int i=0;i<n;i++){
        cin>>r>>c;
        vr.push_back(r);
        vc.push_back(c);
    }
    sort(vr.begin(),vr.end());
    sort(vc.begin(),vc.end());
    vr.push_back(n+1);
    vc.push_back(n+1);
    int x=0,y=0;
    for(int i=0;i<=n;i++){
        if(vr[i]==x){
            rv.push_back(x);
        }
        else{
            for(int j=x+1;j<vr[i];j++){
                rm.push_back(j);
            }
            x=vr[i];
        }
        if(vc[i]==y){
            cv.push_back(y);
        }
        else{
            for(int j=y+1;j<vc[i];j++){
                cm.push_back(j);
            }
            y=vc[i];
        }
    }
    int s=0;
    for(int i=0;i<cv.size();i++){
        s=s+abs(cv[i]-cm[i]);
    }
    for(int i=0;i<rv.size();i++){
        s=s+abs(rv[i]-rm[i]);
    }
    cout<<s;
    return 0;
}