//
// Created by saa on 2021/5/27.
//
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int h=0;
    int w=0;
    int min=300;
    int sum=0;
    cin>>h>>w;
    vector<int> blocks(h*w);

    for(int n=0;n<blocks.size();n++)
    {
        cin>>blocks[n];
        if(blocks[n]<min)
        {
            min=blocks[n];
        }
    }

    for(int n=0;n<blocks.size();n++)
    {
        sum+=blocks[n]-min;
    }

    cout<<sum<<"\n";

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vvint vector<vector<int>>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < (int)v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}


void solve() {
    int h,w;
    cin >> h >> w;
    vvint a(h, vint(w));
    REP(i,h) {
        cin >> a[i];
    }
    int val = INT_MAX;
    REP(i,h) {
        REP(j,w) {
            val = min(val, a[i][j]);
        }
    }
    ll ans = 0;
    REP(i,h) {
        REP(j,w) {
            ans += a[i][j] - val;
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}

