#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
typedef std::vector<string> vstr;
typedef std::pair<long long, long long> pll;
#define INF 1999999999
#define INFLL std::numeric_limits<long long>::max()
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define rep1(i,n) for (long long i = 1; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define errv1(x) cerr << #x <<" "<< x << endl;
#define errv2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl;
#define errv3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl;
#define errv4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl;

int main() {
  ll H, W;
  cin >> H >> W;
  vvll A(H, vll(W));
  rep(i,H){
    rep(j,W){
      cin >> A[i][j];
    }
  }
  
  ll mini = INFLL;
  rep(i,H){
    rep(j,W){
      mini = min(mini, A[i][j]);
    }
  }
  
  ll ans =0;
  rep(i,H){
    rep(j,W){
      ans += A[i][j] - mini;
    }
  }
  cout << ans << endl;
  return 0;                                                                                                               
}

#include <bits/stdc++.h>
using namespace std;

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

long long n, ans, a, b;

int main(){
    n = read();
    for (int i = 1; i <= n; i++)
        a = read(), b = read(), ans += ((a+b) * (b-a+1) / 2);
    printf("%lld\n", ans);
    return 0;
}