#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second
#define pb push_back

using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
//using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
//using ordered_multiset = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
const double eps = 1e-12;
const ll INF = 1e18;


int main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL_DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output_false.txt", "w", stdout); //outs
#endif
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (auto& i : a) {
        for (int& j : i) cin >> j;
    }
    int minv = a[0][0];
    for (auto& i : a) {
        for (int& j : i) minv = min(minv, j);
    }
    ll ans = 0;
    for (auto& i : a) {
        for (int& j : i) ans += j - minv;
    }
    cout << ans << endl;
    return 0;
}
/**
 * author  : UshanGhosh
 * created : 2020-12-19 18:04:46
**/ 

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

#define    ll      long long
#define    pii     pair<int,int>
#define    vii     vector<int>
#define    vcc     vector<char>
#define    pll     pair<long long, long long>
#define    mem     memset
#define    sof     sizeof
#define    co1     __builtin_popcountll
#define    PB      push_back
#define    UB      upper_bound
#define    LB      lower_bound
#define    MP      make_pair
#define    TS      to_string
#define    F       first
#define    S       second
#define    pi      acos(-1)
#define    mod     (long long)1000000007
#define    inf     (long long)1e18
#define    endl    '\n'

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d,e,f,i,j,k,m,n,o,x,y;
    cin>>n>>m;
    ll pans = inf;
    ll sum = 0;
    for(i=0;i<n*m;i++){
        cin>>a;
        pans = min(pans, a);
        sum += a;
    }   
    cout<<sum-pans*n*m;
}