#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#include <complex>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    ll mi=2,ma=2*n;
    chmax(mi,2+k);
    chmin(ma,k+2*n);
    ll ans=0;
    //cout << mi << " " << ma << endl;
    for(ll i=mi;i<=ma;i++){
        ll res=0;
        if(i-n<1) res+=(i-1);
        else res+=(2*n-i+1);
        
        ll j=i-k;
        if(j-n<1) res*=(j-1);
        else res*=(2*n-j+1);
        
        ans+=res;
    }
    cout << ans << endl;
}



#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> P(M);
    for (auto &[x, y] : P) cin >> x >> y;

    vector<int> X, Y;
    for (auto &[x, y] : P) {
        X.push_back(x);
        Y.push_back(y);
        Y.push_back(y + 1);
        Y.push_back(y - 1);
    }

    sort(ALL(X));
    X.erase(unique(ALL(X)), X.end());

    Y.push_back(N);
    sort(ALL(Y));
    Y.erase(unique(ALL(Y)), Y.end());

    vector<vector<int>> YY(X.size());
    for (auto &[x, y] : P) {
        int idx = lower_bound(ALL(X), x) - X.begin();
        YY[idx].push_back(y);
    }

    vector<int> dp(Y.size());
    dp[lower_bound(ALL(Y), N) - Y.begin()] = 1;

    for (auto &yy : YY) {
        vector<pair<int, int>> nx;
        for (auto &y : yy) {
            int idx = lower_bound(ALL(Y), y) - Y.begin();
            
            int next = 0;
            if (idx > 0 && dp[idx - 1]) next = 1;
            if (idx + 1 < (int)Y.size() && dp[idx + 1]) next = 1;
            nx.push_back({idx, next});
        }

        for (auto &[idx, next] : nx) dp[idx] = next;
    }
    cout << accumulate(ALL(dp), 0) << endl;
    return 0;
}
