#include <bits/stdc++.h>

using namespace std;

int main(){
  int H, W;
  while(scanf("%d%d", &H, &W) > 0){
    int A[H][W], min_A = 110;

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	scanf("%d", &A[i][j]);
	min_A = min(min_A, A[i][j]);
      }
    }

    int ans = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	ans += A[i][j] - min_A;
      }
    }

    printf("%d\n", ans);
  }
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <optional>
#include <utility>
#include <vector>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    int H, W; std::cin >> H >> W;
    int sum = 0;
    int m = std::numeric_limits<int>::max();
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j){
        int a; std::cin >> a;
        sum += a; if(m > a) m = a;
    }
    std::cout << (sum - (H * W * m)) << '\n';
    return 0;
}