#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
    int H, W, Abuf;
    int minNum = 101;
    int sumNum = 0;
    cin >> H >> W;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> Abuf;
            minNum = min(minNum, Abuf);
            sumNum +=Abuf;
        }
    }
    cout << sumNum - minNum*H*W << endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
const long long INF = 1LL << 60;
const int inf = 1001001001;
const ll mod = 1000000007;

int main()
{
    int h, w;
    cin >> h >> w;
    vi a(h*w); rep(i,h*w) cin >> a[i];
    sort(ALL(a));
    int min = a[0];
    int res = 0;
    for (int i = 1; i < h*w; i++) {
        res += a[i] - min;
    }
    cout << res << endl;
}