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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    map<int,int>mp;
    vector<int>v;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            int temp;
            cin>>temp;
            v.push_back(temp);
            mp[temp]++;
        }
    }
    int low = *min_element(v.begin(),v.end());
    int ans =0;
    for(auto &it:mp)
    {
        if(it.first!=low)
        {
            ans+=(it.first-low)*it.second;
        }
    }
    cout<<ans<<"\n";
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

const ll inf = 1e9 + 9;
const ll maxn = 1e5+100;
const ll mod = 1e9+7;
const ld eps = 1e-6;

//-------------------------------------------------------------------------
int n, m, mn, sum;

void solve() {
    cin >> n >> m;
    mn = 110;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x;
            cin >> x;
            sum += x;
            mn = min(mn, x);
        }
    }
    cout << sum - mn * n * m << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
