#include <bits/stdc++.h>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int h, w;
    int min_n = 100000;
    int ans = 0;
    cin >> h >> w;
    vector<int> a(h*w);
    rep(i, h*w){
        cin >> a[i];
        min_n = min(min_n, a[i]);
    }
    rep(i, h*w){
        ans+=a[i]-min_n;
    }
    cout << ans << endl;
    return 0;
}

#pragma region template
// clang-format off

#if __has_include(<src.hpp>)
#include <src.hpp>  // precompiled header
#endif

#ifdef __INTELLISENSE__
#define NDEBUG
namespace std {
#endif

#include <cassert>
#include <cctype>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#ifdef __INTELLISENSE__
  using namespace std;
}
#endif

#ifdef LOCAL_DEBUG
#include <debugger.hpp>  // https://gist.github.com/naskya/d28b74e1df8816740c6fcbf0c66c5693
#define see(...) debugger::print(#__VA_ARGS__, __VA_ARGS__)
#define here(label) debugger::output << "[Debug] " << #label << (std::string(#label).size() ? " | " : "") << "line " << __LINE__ << " (" << __func__ << ")\n"
#define com(msg) debugger::output << "[Debug] " << msg << "\n"
#define local(x) do{x} while(0)
#define alter(x, y) x
#else
#define see(...) (static_cast<void>(0))
#define here(label) (static_cast<void>(0))
#define com(msg) (static_cast<void>(0))
#define local(x) (static_cast<void>(0))
#define alter(x, y) y
#endif

#if (!defined LOCAL_DEBUG) || (defined NOWARN)
#define warn(msg) (static_cast<void>(0))
#else
#define warn(msg) debugger::output << "[Warning] " << msg << "\n          \033[0;35m#define NOWARN\033[0m to suppress this warning.\n"
#endif

#if (defined LOCAL_DEBUG) || (defined LOCAL_NDEBUG) || (defined __INTELLISENSE__)
#define NOEXCEPT
#define M_assert(expr) assert(expr)
#define O_assert(expr) assert(expr)
#else
#define NOEXCEPT noexcept
#define M_assert(expr) do{if(__builtin_expect(!(expr), 0)) {long long *p = (long long*) std::malloc(1 << 30); for (int i = 0; i < static_cast<int>((1 << 30) / sizeof(long long)); p[i] = 1, i += (1 << 9)); std::fprintf(stderr, "%lld", *p);}} while(0)
#define O_assert(expr) do{if(__builtin_expect(!(expr), 0)) for(int i = 0; i < (1 << 24); i++) std::puts("Hello, world!");} while(0)
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rng(i, f, t, s) for (int i = (f); ((s) > 0) ? (i < (int)(t)) : (i > (int)(t)); i += (s))
#define erng(i, f, t, s) for (int i = (f); ((s) > 0) ? (i <= (int)(t)) : (i >= (int)(t)); i += (s))

[[maybe_unused]] constexpr int       INF   = 1000000005;
[[maybe_unused]] constexpr long long LINF  = 1000000000000000005LL;
[[maybe_unused]] constexpr double    EPS   = 1e-9;
[[maybe_unused]] constexpr int       dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
[[maybe_unused]] constexpr int       dx[8] = {0, 1, 0, -1, -1, 1, 1, -1};

template <class S, class T, class... U, class V = std::common_type_t<S, T, U...>> constexpr V Min(S a, T b, U... c) {
  if constexpr (sizeof...(U) > 0) return std::min((V) a, (V) Min(b, c...)); else return std::min((V) a, (V) b);
}
template <class S, class T, class... U, class V = std::common_type_t<S, T, U...>> constexpr V Max(S a, T b, U... c) {
  if constexpr (sizeof...(U) > 0) return std::max((V) a, (V) Max(b, c...)); else return std::max((V) a, (V) b);
}

// clang-format on
#pragma endregion

void solve(long long H, long long W, std::vector<std::vector<long long>> A) {
  int ans = 0;
  int min = INF;
  rep(i, H) {
    rep(j, W) {
      min = Min(min, A[i][j]);
    }
  }
  rep(i, H) {
    rep(j, W) {
      ans += A[i][j] - min;
    }
  }
  std::cout << ans << "\n";
}

int main() {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
  long long H;
  std::scanf("%lld", &H);
  long long W;
  std::scanf("%lld", &W);
  std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      std::scanf("%lld", &A[i][j]);
    }
  }
#pragma GCC diagnostic pop
  solve(H, W, std::move(A));
}
