#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
    int main(){
    int N, k;
    bool prop=true;
    int i=1;
    cin>>N;
    int x[N+1];
    int y[N+1];
    while(i<=N) {
        cin>>k;
        x[i]=k;
        cin>>k;
        y[i]=k;
        i++;
    }
    int ix=1;
    int iy=1;
    sort(x, x+N+1);
    sort(y, y+N+1);
    while(ix<=N) {
        int px = i + 1;
        while(px<=N) {
            if(x[ix]==x[px]){
               for(int ipp=1;ipp<=N;ipp++){
                   prop=true;
                   for(int ppp=1;ipp<=N;ppp++){
                       if(x[ipp]==ppp){
                           prop = false;
                       }
                   }
                   if(prop){
                       k+=abs(x[ix]-ipp);
                       x[ix]=ipp;
                   }
               }
            }
            px++;
        }
        ix++;
    }
    while(iy<=N) {
        int py = i + 1;
        while(py<=N) {
            if(y[iy]==y[py]){
               for(int ipp=1;ipp<=N;ipp++){
                   prop=true;
                   for(int ppp=1;ipp<=N;ppp++){
                       if(y[ipp]==ppp){
                           prop = false;
                       }
                   }
                   if(prop){
                       k+=abs(y[iy]-ipp);
                       y[iy]=ipp;
                   }
               }
            }
            py++;
        }
        iy++;
    }
    cout<<k;
}