#include <bits/stdc++.h>
using namespace std;
#define ll long long

void print(vector<int> &a){for(auto l : a) cout<<l<<" "; cout<<'\n';}

void solve(){
    int n,m;
    cin>>n>>m;
    int a[n][m];
    int mi = INT_MAX;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j) cin>>a[i][j], mi=min(mi,a[i][j]);
    }
    int ans = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j) ans+= a[i][j] - mi;
    }
    cout<<ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("lex.in", "r", stdin);//freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}

#include <bits/stdc++.h>
#include <stdlib.h>
#include <ctype.h>
#include <regex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())


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

    vector<vector<int>> data(H, vector<int>(W));

    
    
    rep(i,H){
        rep(j,W){
            cin >> data.at(i).at(j);
        }
    }
    int min = data.at(0).at(0);


    rep(i,H){
        rep(j,W){
            if(data.at(i).at(j) < min){
                min = data.at(i).at(j);
            }
        }
    }

    int count = 0;
    rep(i,H){
        rep(j,W){
            count += (data.at(i).at(j) - min);
        }
    }
    cout << count;

}