#include<bits/stdc++.h>
using namespace std;
int m(int i){
    if(i<0){
        return -i;
    }
    return i;
}
int dist[2001][2001];
int neok[2001][2001];
tuple<int,int,int> a[2001];
tuple<int,int,int> b[2001];
vector< pair<int,int> > r[2001];
priority_queue< pair<int,int> > q;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a[i]=make_tuple(x,y,i);
        b[i]=make_tuple(y,x,i);
    }
    sort(a,a+n);
    sort(b,b+n);
    for(int i=0;i<n-1;i++){
        if(get<0>(a[i])==get<0>(a[i+1])){
            r[get<2>(a[i])].push_back(make_pair(m(get<0>(a[i])-get<0>(a[i+1]))+m(get<1>(a[i])-get<1>(a[i+1])),get<2>(a[i+1])));
            r[get<2>(a[i+1])].push_back(make_pair(m(get<0>(a[i])-get<0>(a[i+1]))+m(get<1>(a[i])-get<1>(a[i+1])),get<2>(a[i])));
        }
        if(get<0>(b[i])==get<0>(b[i+1])){
            r[get<2>(b[i])].push_back(make_pair(m(get<0>(b[i])-get<0>(b[i+1]))+m(get<1>(b[i])-get<1>(b[i+1])),get<2>(b[i+1])));
            r[get<2>(b[i+1])].push_back(make_pair(m(get<0>(b[i])-get<0>(b[i+1]))+m(get<1>(b[i])-get<1>(b[i+1])),get<2>(b[i])));
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i].first==a[j].first or a[i].second==a[j].second){
                r[i].push_back(make_pair(m(a[i].first-a[j].first)+m(a[i].second-a[j].second),j));
                r[j].push_back(make_pair(m(a[i].first-a[j].first)+m(a[i].second-a[j].second),i));
            }
        }
    }
    */
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            neok[i][j]=1e9;
            dist[i][j]=-1;
            neok[j][i]=1e9;
            dist[j][i]=-1;
        }
    }
    int max1=-1;
    /*p.push(make_pair(1,2));
    p.push(make_pair(3,2));
    p.push(make_pair(-1,2));
    cout<<p.top().first;
    */
    for(int st=0;st<n;st++){
        q.push(make_pair(0,st));
        while(!q.empty()){
            int curr=q.top().second;
            int d=-q.top().first;
            if(dist[st][curr]!=-1){
                q.pop();
                continue;
            }
            //cout<<"dist do "<<curr<<" "<<d<<endl;
            dist[st][curr]=d;
            max1=max(max1,dist[st][curr]);
            for(int i=0;i<r[curr].size();i++){
                int to=r[curr][i].second;
                if(neok[st][to]>dist[st][curr]+r[curr][i].first){
                    neok[st][to]=dist[st][curr]+r[curr][i].first;
                    //cout<<neok[st][to]<<" "<<to<<endl;
                    q.push(make_pair(-neok[st][to],to));
                }
            }
            q.pop();
        }
    }
    cout<<max1;
    return 0;
}
/*
5
4 3
3 3
2 3
3 2
2 2


*/
