#include <bits/stdc++.h>
using namespace std;

int a[100][100];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w;
    cin >> h >> w;

    int mn = 1e9, total = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
            mn = min(mn, a[i][j]);
            total += a[i][j];
        }
    }
    cout << total - h*w*mn;
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define mp map<ll, ll>
#define um unordered_map<ll, ll>
#define st set<ll> 
#define us unordered_set<ll>
#define vt vector<ll>
#define vp vector<pll>
#define pll pair<ll, ll>
#define fl(i, x, y) for(ll i=x;i<y;++i)
#define flr(i, x, y) for(ll i=x;i>=y;--i)
#define endl "\n"
#define speedup ios_base::sync_with_stdio(false), cin.tie(NULL)

void  solve()
{
    ll n,m;
    cin>>n>>m;
    ll a[n][m], mn=LONG_MAX, s=0;
    fl(i, 0, n)
    {
        fl(j, 0, m)
        {
            cin>>a[i][j];
            mn = min(mn, a[i][j]);
        }
    }
    fl(i, 0, n)
    {
        fl(j, 0, m)
        s += (abs(a[i][j]-mn));
    }
    cout<<s<<endl;
}

int main()
{
    speedup;
    #ifndef ONLINE_JUDGE
        freopen("E:\\competitive programming\\input.txt", "r", stdin);
        freopen("E:\\competitive programming\\output.txt", "w", stdout);
    #endif
    ll tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
	return 0;
}
