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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi,ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int H,W,grid[501][501];
int main(){
	fast;
	cin >> H >> W;
  	int mn = 1e9, ans = 0;
  	FOR(i,1,H) FOR(j,1,W){
		cin >> grid[i][j]; mn = min(mn, grid[i][j]);
      	ans += grid[i][j];
    }
  	
  	cout << ans - mn * H * W;
  
  	
  
	
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int H, W;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> H >> W;
    vector<vector<ll>> a(H, vector<ll>(W));
    ll mmin = 101;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            {
                cin >> a[i][j];
                mmin = min(mmin, a[i][j]);
            }
        }
    };
    ll s = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            s += abs(a[i][j] - mmin);
        }
    }
    cout << s << endl;
    return 0;
}
