    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
    using namespace __gnu_pbds;

    struct custom_hash {
        static uint64_t splitmix64(uint64_t x) {
            // http://x...content-available-to-author-only...i.it/splitmix64.c
            x += 0x9e3779b97f4a7c15;
            x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
            x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
            return x ^ (x >> 31);
        }
 
        size_t operator()(uint64_t x) const {
            static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
            return splitmix64(x + FIXED_RANDOM);
        }
    };
 

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;        
 

    #define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define pb          push_back
    #define eb          emplace_back
    #define vi          vector<int>
    #define vvi         vector<vector<int>>
    #define vii         vector<pii>
    #define pii         pair<int,int>
    #define all(a)      (a).begin(),(a).end()
    #define ff          first
    #define ss          second
    #define sp(n)       setprecision(n)<<fixed
    #define endl        '\n' 
    #define umap        unordered_map<long long, vii, custom_hash>

    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
      template <typename Arg1>
      void __f(const char* name, Arg1&& arg1){
          std::cerr << name << " : " << arg1 << endl;
      }
      template <typename Arg1, typename... Args>
      void __f(const char* names, Arg1&& arg1, Args&&... args){
          const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
      }

    // -------------------Standard Traversal Moves---------------------
    // vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
    // vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
    // vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
    // ----------------------------------------------------------------


    // #define int         long long
    const int N = 2e5 + 5, K = 20, MOD = 1000000007, mod = 998244353;
    // const long long INF = LLONG_MAX/2;
    const int INF = INT_MAX/2;
    const double pi = 3.141592653589793;
    
    int n,m,x,y;
    int a[105][105];
    
    void solve(){
        cin>>n>>m;
        int sum = 0, mn = INF;;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=m; j++){
                cin>>a[i][j];
                mn = min(mn, a[i][j]);
                sum += a[i][j];
            }
        }
        int ans = sum - (mn*n*m);
        cout<<ans<<endl;
    }

    int32_t main()
    {
        IOS;
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();
        }
        return 0;
    }
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  int n = h*w;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int ans = 0;
  for(int i = 0;i < n;i++){
    ans += a.at(i)-a.at(0);
  }
  cout << ans << endl;
}