#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<string.h>
#include<set>
#include<algorithm>
#define Doura() ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL)
#define ll long long
using namespace std;
int main()
{
    Doura();
    int h,w,i,j,m=1000;
    cin>>h>>w;
    int a[h][w];
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin>>a[i][j];
            m=min(m,a[i][j]);
        }
    }
    int cnt=0;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cnt+=a[i][j]-m;
        }
    }
    cout<<cnt<<endl;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using ll=long long;

const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

// cout << fixed << setprecision(15) << ans << endl;
// using mint = modint1000000007;

////////////////////////////////////////////////////////////////////////////////////////////

bool cmp0(const tuple<ll, ll, int> &a, const tuple<ll, ll, int> &b) {
  return get<0>(a) < get<0>(b);
}
bool cmp1(const tuple<ll, ll, int> &a, const tuple<ll, ll, int> &b) {
  return get<1>(a) < get<1>(b);
}

int main() {
  int n;cin>>n;
  vector<tuple<ll, ll, int>> xy;
  rep(i, n) {
    ll x, y;cin>>x>>y;
    xy.push_back(make_tuple(x, y, i));
  }
  vector<tuple<ll, ll, int>> v0 = xy;
  sort(all(v0), cmp0);
  vector<tuple<ll, ll, int>> v1 = xy;
  sort(all(v1), cmp1);
  vector<int> ind;
  if(get<0>(v0[n-1]) - get<0>(v0[0]) > get<1>(v1[n-1]) - get<1>(v1[0])) {
    ind.push_back(get<2>(v0[0]));
    ind.push_back(get<2>(v0[n-1]));
  } else {
    ind.push_back(get<2>(v1[0]));
    ind.push_back(get<2>(v1[n-1]));   
  }
  // cout << ind[0] << endl;
  // cout << ind[1] << endl;
  ll ans = -INF;
  rep(i, 2) {
    vector<tuple<ll, ll, int>> temp = xy;
    temp.erase(temp.begin() + ind[i]);
    vector<tuple<ll, ll, int>> v0 = temp;
    sort(all(v0), cmp0);
    vector<tuple<ll, ll, int>> v1 = temp;
    sort(all(v1), cmp1);
    chmax(ans, max(get<0>(v0[n-2]) - get<0>(v0[0]), get<1>(v1[n-2]) - get<1>(v1[0])));
  }
  cout << ans << endl;

}