#include #include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) #define itrep(itr, st) for(auto itr = st.begin(); itr != st.end(); itr++) #define all(x) x.begin(), x.end() #define lb(A, x) (lower_bound(all(A), x) - A.begin()) #define ub(A, x) (upper_bound(all(A), x) - A.begin()) using namespace std; using ll = long long; template using V = vector; template using VV = V >; int main(void) { ll n, m; cin >> n >> m; set xst = {}, yst = {}; rep(i, 0, m) { ll X, Y; cin >> X >> Y; xst.insert((X - 1) + (Y - 1)); yst.insert((X - 1) - (Y - 1)); } VV xv(2, V({})); itrep(itr, xst) { ll x = *itr; xv[x & 1].push_back(x); } ll ans = 0; itrep(itr, xst) { ll x = *itr; ans += min(x, n - 1) - max(-n + 1 + x, (ll)0) + 1; } itrep(itr, yst) { ll y = *itr; int b = abs(y) & 1; ans += min(n - 1 + y, n - 1) - max(y, (ll)0) + 1; auto l = lb(xv[b], max(y, -y)); auto r = ub(xv[b], min(2 * (n - 1) - y, 2 * (n - 1) + y)); ans -= r - l; } cout << ans << endl; return 0; }