#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int h,w,sum=0,mx=998244353;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int in;
      cin>>in;
      sum+=in;
      mx=min(mx,in);
    }
  }
  cout<<sum-mx*h*w<<endl;
}
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  map<int, int> cnt;
  int cur = 0;
  fore(i, 0, n) fore(j, 0, m) {
    int num;
    cin >> num;
    cnt[num]++;
    cur += num;
  }
  auto it = cnt.begin();
  cout << cur - n * m * (*it).first << '\n';

  return 0;
}