#include<bits/stdc++.h>
using namespace std;
long long a,b,c[100010],sum=0,m=101;
int main(){
cin>>a>>b;
a*=b;
for(long long i=0;i<a;i++){
	cin>>c[i];
	if(c[i]<m)m=c[i];
	sum+=c[i];
}
sum-=m*a;
cout<<sum;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

// Vectors
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define print(x) cout << x << "\n"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    // find min
    int m = INT_MAX;  // min
    int arr[101][101];

    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            cin >> arr[i][j];
        }
    }

    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            m = min(arr[i][j], m);
        }
    }

    int ans = 0;
    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            if (arr[i][j] > m) {
                ans += arr[i][j] - m;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}