#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; int main() { lint N, M; cin >> N >> M; lint a=0, b=0, c=0, x, y, z; set s, t, so, se, to, te; rep(i, M) { cin >> x >> y; s.insert(y-x); t.insert(x+y-2); if ((y-x)%2) so.insert(y-x); else se.insert(y-x); if ((x+y)%2) to.insert(x+y-2); else te.insert(x+y-2); } vi vo, ve, wo, we; for (auto l : so) vo.pb(l); for (auto l : se) ve.pb(l); for (auto l : to) wo.pb(l); for (auto l : te) we.pb(l); // vout(vo); // vout(ve); for (auto l : s) { c += N-abs(l); // x = N-1-abs(l); // y = N-1+abs(l); // if (l%2) { // auto o = lower_bound(all(wo), x); // auto u = upper_bound(all(wo), y); // c -= u-o; // } else { // auto o = lower_bound(all(we), x); // auto u = upper_bound(all(we), y); // c -= u-o; // } } for (auto l : t) { c += N-abs(N-1-l); x = abs(N-1-l)-(N-1); y = N-1-abs(N-1-l); // list(l) // list(x) // show(y) if (l%2) { auto o = lower_bound(all(vo), x); auto u = upper_bound(all(vo), y); c -= u-o; } else { auto o = lower_bound(all(ve), x); auto u = upper_bound(all(ve), y); c -= u-o; } } std::cout << c << '\n'; }