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

int main(){
  int H,W,min=100,answer=0;
  cin>>H>>W;
  vector<int> A(H*W);
  for(int i=0;i<H*W;i++){
   cin>>A[i];
    if(min>A[i])min=A[i];
  }
  for(int i=0;i<H*W;i++){
   answer=answer+(A[i]-min);
  }
  cout<<answer<<endl;
}
/*..........UNPROFESSIONAL..........*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fk(i,start,end) for(ll i=start;i<ll(end);i++)
typedef long long int ll;
string A="YES";
string B="NO";

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n,m;
     cin>>n>>m;
     ll a[n][m];
     ll mi=101;
     fk(i,0,n)
     {
     	fk(j,0,m)
     	{
     		cin>>a[i][j];
     		mi=min(mi,a[i][j]);
     	}
     }
     ll count=0;
     fk(i,0,n)
     {
     	fk(j,0,m)
     	{
     		count+=(a[i][j]-mi);
     	}
     }
     cout<<count;



  


  return 0;
}