#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int H, W;
	cin >> H >> W;
	vector<vector<int>> A(H, vector<int>(W, 0));
	int ans = 0;
	int min_val = 101;
	rep(i, H) {
		rep(j, W) {
			cin >> A[i][j];
			min_val = min(min_val, A[i][j]);
		}
	}

	rep(i, H) {
		rep(j, W) {
			ans += A[i][j] - min_val;
		}
	}
	
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<int> A(H*W);
  for(int i = 0;i < H*W;i++){
    cin >> A.at(i);
  }
  
  int m = 100;
  for(int i = 0;i < H*W;i++){
    m = min(m, A.at(i));
  }
  
  int ans = 0;
  for(int i = 0;i < H*W;i++){
    ans += A.at(i) - m;
  }
  
  cout << ans << endl;
}