#include<bits/stdc++.h>

using namespace std;

long long int n,a[200],b[200],c[200],br=0;

vector<long long int> f;
vector<long long int> d;

bool bs(long long int x,long long int niz[])
{
    long long int levo=1,desno=n,mid;
    while(levo<=desno){
        mid = (levo+desno)/2;
        if(niz[mid] == x) return true;
        if(niz[mid] < x) levo = mid+1;
        else desno = mid-1;
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n;
    for(long long int i = 1;i<=n;i++) cin>>a[i]>>b[i];
    sort(a+1,a+n+1); sort(b+1,b+n+1);

    for(long long int i=1;i<=n;i++) c[i] = i;

    for(long long int i=1;i<=n;i++){
        if(!bs(c[i],a)){
            f.push_back(c[i]);
        }
    }
    for(long long int i=1;i<=n-1;i++){
        if(a[i]==a[i+1]){
            d.push_back(a[i]);
        }
    }
    sort(f.begin(),f.end()); sort(d.begin(),d.end());
 /*   for(int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    for(int i=0;i<d.size();i++) cout<<d[i]<<" ";
*/
    long long int k = f.size() - 1;
    while(f.size()!=0){
        br+=abs(f[k]-d[k]);
        f.pop_back(); d.pop_back();
        k--;
    }

    for(long long int i=1;i<=n;i++){
        if(!bs(c[i],b)){
            f.push_back(c[i]);
        }
    }
    for(long long int i=1;i<=n-1;i++){
        if(b[i]==b[i+1]){
            d.push_back(b[i]);
        }
    }
    sort(f.begin(),f.end()); sort(d.begin(),d.end());
 /*   for(int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    for(int i=0;i<d.size();i++) cout<<d[i]<<" ";
*/
    k = f.size() - 1;
    while(f.size()!=0){
        br+=abs(f[k]-d[k]);
        f.pop_back(); d.pop_back();
        k--;
    }
    cout<<br;
    return 0;
}