#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,int>

int main(){
    ll B,C;
    cin >> B >> C;
    ll Al,Ar,Bl,Br;
    ll ans;
    Al = B - C/2;
    Ar = max(B,B + (C-2)/2);
    Bl = (-1)*B-(C-1)/2;
    Br = (-1)*B+(C-1)/2;
    if(B>0){
        ans = Ar-Al+1+Br-Bl+1;
        if(Br>=Al) ans -= (Br-Al+1);
    }
    if(B<0){
        ans = Ar-Al+1+Br-Bl+1;
        if(Ar>=Bl) ans -= (Ar-Bl+1);
    }
    if(B==0){
        ans = Br - Al +1;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
constexpr int INF = 1000000010;

int main() {
    int h, w;
    cin >> h >> w;
    int mn = INF;
    mat a(h, vec(w));
    rep(i, h) rep(j, w) {
        int x;
        cin >> x;
        a[i][j] = x;
        mn = min(mn, x);
    }

    int res = 0;

    rep(i, h) rep(j, w) res += (a[i][j] - mn);

    cout << res << endl;
    return 0;
}
