// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define lll __int128
// #define mp std::make_pair
#define pii std::pair<int,int>
#define pll std::pair<ll,ll>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define mtp std::make_tuple

const double PI = atan(1.0) * 4;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const int maximum  = numeric_limits<int>::max();
const int minimum  = numeric_limits<int>::min();
const int mod = 1e9 + 7 ;
const int INF = 1e9 ;
ll gcd (ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}


// function<void(int, int)> dfs = [&](int u , int p) {
// };

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T ;
	// cin >> T ;
	T = 1 ;
	while (T--) {
		int n , m ;
		cin >> n >> m ;
		int mn = 105 ;
		vector<vector<int>> a(n , vector<int>(m))  ;
		for (int i = 0 ; i < n ; i++) {
			for (int j = 0 ; j < m ; j++) {
				cin >> a[i][j] ;
				mn = min(mn , a[i][j]) ;
			}
		}
		// cout << mn << "\n" ;
		int ans = 0 ;
		for (int i = 0 ; i < n; i++) {
			for (int j = 0 ; j < m ; j++) {
				ans += (a[i][j] - mn) ;
			}
		}
		cout << ans << "\n" ;








	}





	return 0 ;


}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
int ans;
signed  main()
{
    cin>>n>>k;

    for(int i=2;i<=2*n;i++)
    {
        int b=i-k;
        if(b>=2&&b<=2*n)
        {
            int l=0;
            if(i>n)
            {
                int cha=i-n;
                l=(n-cha+1);
            }
            else
            {
                l=i-1;

            }
             // if(l%2==0)l--;
        //    l*=2;
         //   if(i%2==0)l--;
            int r=0;
            if(b>n)
            {
                int cha=b-n;

                r=(n-cha+1);
               // if(r%2==0)

            }
            else
            {
                r=b-1;

            }
           //  if(r%2==0)r--;
       //    r*=2;
        //   if(b%2==0)r--;

            ans+=l*r;
        //   printf("%lld %lld\n",l,r);

        }

    }
    cout<<ans;
}
