#include #define itrep(itr, st) for(auto itr = st.begin(); itr != st.end(); itr++) using namespace std; using ll = long long; int main(){ ll n, m; cin >> n >> m; set xst = {}, yst = {}; for(int i = 0; i < m; ++i){ ll X, Y; cin >> X >> Y; xst.insert((X - 1) + (Y - 1)); yst.insert((X - 1) - (Y - 1)); } ll ans = 0; vector > que(2, deque({})); itrep(itr, xst) { ll x = *itr; ans += min(x, n - 1) - max(x - (n - 1), 0ll) + 1; que[x & 1].push_back(x); } vector yvec = {}; itrep(itr, yst) { yvec.push_back(abs(*itr)); } sort(yvec.begin(), yvec.end()); for(auto y : yvec){ ll lv = y, rv = 2 * (n - 1) - y; int b = y & 1; ans += min(n - 1 + y, n - 1) - max(y, 0ll) + 1; while (!que[b].empty() && que[b].back() > rv) { que[b].pop_back(); } while (!que[b].empty() && que[b].front() < lv) { que[b].pop_front(); } ans -= que[b].size(); } cout << ans << endl; return 0; }