#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <numeric>
#include <unordered_set>
using namespace std;

int main(){
    int h,w;    cin >> h >> w;
    vector<vector<int> > block(h,vector<int>(w));
    int min_block;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> block[i][j];
            min_block = min(min_block,block[i][j]);
        }
    }
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans += block[i][j]-min_block;
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

template <class T>
bool chmin(T& a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    else
        return false;
}

int main()
{
    int h, w;
    cin >> h >> w;

    int ans = 0;
    int mx = 101;

    rep(_, h * w) {
        int a;
        cin >> a;
        chmin(mx, a);
        ans += a;
    }
    ans -= mx * h * w;

    cout << ans << "\n"s;

    return 0;
}
