#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;
    k=0; 
    int px;
    while(ix<=N) {
        px = ix + 1;
        while(px<=N) {
            
            if(x[ix]==x[px]){
               for(int ipp=1;ipp<=N;ipp++){
                   prop=true;
                   for(int ppp=1;ppp<=N;ppp++){
                       if(x[ppp]==ipp){
                           prop = false;
                           
                   }
                   }
                   if(prop==true){
                       
                       k=k+abs(x[ix]-ipp);
                       x[ix]=ipp;
                       break;
                   }
               }
            }
            px++;
        }
        ix++;
    }
    int py;
    while(iy<=N) {
        py = iy + 1;
        while(py<=N) {
            if(y[iy]==y[py]){
               for(int ipp=1;ipp<=N;ipp++){
                   prop=true;
                   for(int ppp=1;ppp<=N;ppp++){
                       if(y[ppp]==ipp){
                           prop = false;
                           
                       
                   }
                   if(prop==true){
                       
                       k=k+abs(y[iy]-ipp);
                       y[iy]=ipp;
                       break;
                   }
               }
            }
        
        }
        py++;
    }
    iy++;
    }
    cout<<k;

}