#include #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() using namespace std; using ll = long long; template using V = vector; 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)); } ll ans = 0; V > que(2, deque({})); itrep(itr, xst) { ll x = *itr; ans += min(x, n - 1) - max(-n + 1 + x, 0ll) + 1; que[x & 1].push_back(x); } V yv = {}; itrep(itr, yst) { yv.push_back(abs(*itr)); } sort(all(yv)); for (auto y : yv) { ll lv = y, rv = 2 * (n - 1) - y; int b = abs(y) & 1; ans += min(n - 1 + y, n - 1) - max(y, 0ll) + 1; while (que[b].empty() == false and que[b].back() > rv) { que[b].pop_back(); } while (que[b].empty() == false and que[b].front() < lv) { que[b].pop_front(); } ans -= que[b].size(); } cout << ans << endl; return 0; }