#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL << 60;

int main(){
    int h, w;
    cin >> h >> w;
    vector<int> a(h*w);
    int min_a = 100;
    rep(i, h*w){
        cin >> a[i];
        min_a = min(a[i], min_a);
    }
    int ans = 0;
    rep(i, h*w){
        ans += a[i] - min_a;
    }
    cout << ans << endl;

}
#include <bits/stdc++.h>
using namespace std;

int main(){
   int h, v;
   cin>>h>>v;
   int counter  = h*v;
   int m;
   cin>>m;
   int sum = m;
   for(int i=1;i<counter;i++){
    int x;
    cin>>x;
    sum += x;
    if(m>x){
        m =x;
    }
   }
   int ans;
   ans = sum - m*counter;
   cout<<ans;
}
