#include<bits/stdc++.h>
using namespace std;
const int MAXN=2048;
int n;
int x[MAXN];
int y[MAXN];
int dist[MAXN];
bool used[MAXN];
vector<pair<int,int> >pointsx[MAXN];
vector<pair<int,int> >pointsy[MAXN];
vector<pair<int,int> >g[MAXN];
void dijkstra(int u)
{
    for(int i=0;i<MAXN;i++)dist[i]=(int)1e9;
    for(int i=0;i<MAXN;i++)used[i]=0;
    priority_queue<pair<int,int> >pq;
    pq.push({0,u});dist[u]=0;
    while(!pq.empty())
    {
        u=pq.top().second;pq.pop();
        if(used[u])continue;used[u]=1;
        for(int i=0;i<g[u].size();i++)
        {
            if(dist[u]+g[u][i].second<dist[g[u][i].first])
            {
                dist[g[u][i].first]=dist[u]+g[u][i].second;
                pq.push({-dist[u]-g[u][i].second,g[u][i].second});
            }
        }
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i]>>y[i];
        pointsx[x[i]].push_back({y[i],i});
        pointsx[y[i]].push_back({x[i],i});
    }
    for(int i=0;i<MAXN;i++)
    {
        sort(pointsx[i].begin(),pointsx[i].end());
        for(int j=0;j<pointsx[i].size();j++)
        {
            if(j!=0)
            {
                g[pointsx[i][j].second].push_back({pointsx[i][j-1].second,pointsx[i][j].first-pointsx[i][j-1].first});
            }
            if(j!=pointsx[i].size()-1)
            {
                g[pointsx[i][j].second].push_back({pointsx[i][j+1].second,pointsx[i][j+1].first-pointsx[i][j].first});
            }
        }
        sort(pointsy[i].begin(),pointsy[i].end());
        for(int j=0;j<pointsy[i].size();j++)
        {
            if(j!=0)
            {
                g[pointsy[i][j].second].push_back({pointsy[i][j-1].second,pointsy[i][j].first-pointsy[i][j-1].first});
            }
            if(j!=pointsy[i].size()-1)
            {
                g[pointsy[i][j].second].push_back({pointsy[i][j+1].second,pointsy[i][j+1].first-pointsy[i][j].first});
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        dijkstra(i);
        for(int j=1;j<=n;j++)
        {
            if(dist[j]<(int)1e9)ans=max(ans,dist[j]);
        }
    }
    if(ans<=0)assert(false);
    cout<<ans<<endl;
return 0;
}
