//by ciwomuli
//enter ICPC WF 2020
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <sstream>
#define LL long long
using namespace std;
template <typename T>
inline void read(T &t)
{
    int f = 0, c = getchar();
    t = 0;
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        t = t * 10 + c - 48, c = getchar();
    if (f)
        t = -t;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args)
{
    read(t);
    read(args...);
}
int h, w;
int main(){
    int sum = 0;
    int mi = 1000;
    read(h, w);
    for (int i = 1; i <= h;i++){
        for (int j = 1; j <= w;j++){
            int a;
            read(a);
            sum += a;
            if(a<mi)
                mi = a;
        }
    }
    cout << sum - mi * h * w;
}
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                                     \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

ll solve(ll h, ll w, vector<vector<ll>> &field)
{
    ll m = 1000;
    REP(i, h) REP(j, w)
    {
        m = min(m, field[i][j]);
    }
    ll res = 0;
    REP(i, h) REP(j, w)
    {
        res += field[i][j] - m;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> field(h, vector<ll>(w, 0));
    REP(i, h) REP(j, w)
    {
        cin >> field[i][j];
    }

    ll res = solve(h, w, field);
    cout << res << '\n';
    return 0;
}
