//*Bismillahir Rahmanir Raheem
//!BlackBeard
#include <bits/stdc++.h>
#include <algorithm>
#define NFS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0)

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define no cout << "no" << endl

#define ll long long
#define ull unsigned long long
#define pb push_back

#define FILL(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fore(arr) for (auto &x : (arr))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x *(y / gcd(x, y))
#define toint(c) c - 48
#define tochar(c) c + 48

#define MAX 2000010
#define MOD 100000007
#define bug cout << "*_*\n"
using namespace std;

template <class T>
void print(vector<T> v)
{
    fore(v) cout << x << ' ';
    cout << endl;
}
void solve()
{
    int h, w, sum = 0, a;
    cin >> h >> w;
    int mn = INT_MAX;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a;
            sum += a;
            mn = min(a, mn);
        }
    }
    int ans = mn * h * w;
    cout << sum - ans << endl;
}

int main()
{
    NFS;
#ifndef ONLINE_JUDGE
    freopen("D:/code/C++/OJ/in.txt", "r", stdin);
    freopen("D:/code/C++/OJ/out.o", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int memo[1<<16];
const string yes="Yes",no="No";



int main(){
  int n,m,k;
  cin>>n>>m;
  vector<int>v(n*m);
  cin>>v.at(0);
  k=v.at(0);
  for(int i=1;i<n*m;i++){
    cin>>v.at(i);
    k=min(k,v.at(i));
  }
  int s=0;
  for(int i=0;i<n*m;i++){
    s+=v.at(i)-k;
  }
  cout<<s<<endl;
}