#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
#define int long long

signed main() {
	int H, W; cin >> H >> W;
	vector<vector<int>>A(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cin >> A[i][j];
	}
	int ans = INF;
	for (int k = 0; k <= 100; k++) {
		int now = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (A[i][j] < k) {
					now = INF;
					break;
				}
				now += A[i][j] - k;
			}
		}
		ans = min(ans, now);
	}
	cout << ans << endl;
}

//00:04
#include <bits/stdc++.h>
using namespace std;
long long inf = 1000000007;
typedef long long ll;

int main(){
    int h, w, small = 101, cnt = 0;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w, 0));
    for(vector<int>& a1:a){
        for(int& v: a1) cin >> v;
    }
    for(int i=0; i<h; ++i){
        for(int& v: a[i]){
            if(v < small) small = v;
        }
    }
    for(int i=0; i<h; ++i){
        for(int& v: a[i]){
            cnt += v - small;
        }
    }
    cout << cnt << endl;
    return 0;
}