#include <stdint.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define FOR_N(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define FOR_R(i, b, e) for (int64_t i = int64_t(b); i < (int64_t)(e); i++)

int main() {
    int64_t H, W;
    cin >> H >> W;

    int64_t A[100][100];
    int64_t min_A = 9999999999;

    FOR_N(i, H) {
        FOR_N(j, W) {
            cin >> A[i][j];
            min_A = min(min_A, A[i][j]);
        }
    }

    int64_t diff = 0;

    FOR_N(i, H) {
        FOR_N(j, W) {
            diff += A[i][j] - min_A;
        }
    }
    cout << diff << endl;

    return 0;
}
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
typedef long long ll;
#define FOR(i, a, b) for(int i=(a); i<(b);i++)
#define REP(i, n) for(int i=0; i<(n);i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a);i--)
#define PER(i, n) for(int i=n-1; i>=0;i--)
using namespace std;






int main() {
  
  ll h, w;
  ll sum, min;
  sum = 0;
  min = 100;
  cin >> h >> w;
  REP(i, h) {
    REP(j, w) {
      ll a;
      cin >> a;
      sum += a;
      min = min > a ? a : min;
    }
  }
  cout << sum - min * h * w;

  return 0;
}