#include #define rep(i, p, n) for (ll i = p; i < (ll)(n); i++) #define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--) using namespace std; using ll = long long; using ld = long double; const double pi = 3.141592653589793; const long long inf = 2 * 1e9; const long long linf = (1LL << 61); const ll mod1 = 1000000007; const ll mod2 = 998244353; 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 using priority_queue_rev = priority_queue, greater>; #include using namespace atcoder; using mint1 = modint1000000007; using mint2 = modint998244353; vector> base = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; void solve() { ll n, m; cin >> n >> m; set A, B; rep(i, 0, m) { ll x, y; cin >> x >> y; x--; y--; A.insert(x + y); B.insert(x - y); } ll ans = 0; vector diffs[2]; for (ll t : B) { ans += n - abs(t); diffs[abs(t) % 2].push_back(t); } for (ll s : A) { ll r = min(s + 1, 2 * (n - 1) - s + 1); ans += r; auto &v = diffs[s % 2]; r--; ans -= (upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), -r)); } cout << ans << endl; } int main() { ////////////////// ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ////////////////// // ll T; // cin >> T; // while (T--) solve(); return 0; }