#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; template using VV = V >; int main(void) { ll n, m; cin >> n >> m; VV p(m, V(2)); set st1 = {}, st2 = {}; rep(i, 0, m) { ll x, y; cin >> x >> y; x--; y--; p[i][0] = x - y; p[i][1] = x + y; st1.insert(p[i][0]); st2.insert(p[i][1]); } VV naname1(2, V({})); VV naname2(2, V({})); itrep(itr, st1) { ll x = *itr; naname1[abs(x) & 1].push_back(x); } itrep(itr, st2) { ll y = *itr; naname2[y & 1].push_back(y); } ll num = 0, dc = 0; st1 = {}; st2 = {}; rep(i, 0, m) { ll x = p[i][0], y = p[i][1]; int b = y & 1; if (st1.find(x) == st1.end()) { num += min(n - 1 + x, n - 1) - max(x, (ll)0) + 1; auto itr1 = lower_bound(all(naname2[b]), max(x, -x)); auto itr2 = upper_bound(all(naname2[b]), min(2 * (n - 1) - x, 2 * (n - 1) + x)); dc += itr2 - itr1; st1.insert(x); } if (st2.find(y) == st2.end()) { num += min(y, n - 1) - max(-n + 1 + y, (ll)0) + 1; auto itr1 = lower_bound(all(naname1[b]), max(-y, y - 2 * (n - 1))); auto itr2 = upper_bound(all(naname1[b]), min(2 * (n - 1) - y, y)); dc += itr2 - itr1; st2.insert(y); } } ll ans = num - dc / 2; cout << ans << endl; return 0; }