#include #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair; using pll = pair; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template using vvector = vector>; template using vvvector = vector>>; template using priority_queuer = priority_queue, greater>; template bool chmax(t &a, u b){if(a bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; void print(); template void print(const vector &); template void print(const pair &); template void print(const t&); template void print(const Head&, const Tail&...); template void println(const vector>&); template void println(const vector&); template void println(const t&); template void println(const Head&, const Tail&...); void println(); void newline(); void print(){ return; } template void print(const vector&x){ for(const t&i:x)print(i); } template void print(const pair&p){ print(p.first); print(p.second); } template void print(const t&x){ if(was_output)cout<<" "; cout< void print(const Head&head,const Tail&...tail){ print(head); print(tail...); } template void println(const vector>&x){ for(vector i:x)println(i); } template void println(const vector&x){ for(const t&i:x)print(i); println(); } template void println(const t&x){ print(x); println(); } void println(){ if(was_output){ cout << endl; was_output = false; } } template void println(const Head&head,const Tail&...tail){ print(head); println(tail...); } void newline(){ was_output = true; println(); } template istream& operator>>(istream&is, vector&x){ for(auto &i:x)is >> i; return is; } template istream& operator>>(istream&is, pair&x){ is >> x.first >> x.second; return is; } template ostream& operator<<(ostream&os, vector &v){ os << "{"; for(t &i:v){ os << i << ", "; } os << "}"; return os; } template t in(){ t res; cin >> res; return res; } template vector sorted(vector line,function comp=[](t a,t b){return a vector reversed(vector line){ reverse(line.begin(),line.end()); return line; } string reversed(string str){ reverse(str.begin(),str.end()); return str; } long long gcd(long long a,long long b){ while(b){ a %= b; swap(a,b); } return a; } long long lcm(long long a,long long b){ return a / gcd(a,b) * b; } class output_initializer{ public: output_initializer(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); } };output_initializer OUTPUT_INITIALIZER_INSTANCE = output_initializer(); } using namespace templates; ll func(){ ll n = in(); int m = in(); method(calc,ll,vector line){ ll res = 0; map adds; set uy; set ux; foreach(i,line){ ll y = i.first; ll x = i.second; if(ux.count(x-y)==0){ res += min(n-x,n-y) - max(1-x,1-y) + 1; ++adds[abs(x-y)+1]; --adds[2*n-abs(x-y)+1]; ux.emplace(x-y); } if(uy.count(x+y)==0){ res += min(n-x,y-1) - max(1-x,y-n) + 1; uy.emplace(x+y); } } int sum = 0; foreach(i,adds){ sum += i.second; i.second = sum; } set used; foreach(i,line){ ll y = i.first; ll x = i.second; ll p = y+x-1; if(used.count(p))continue; used.emplace(p); if(p>n)++p; auto itr = adds.upper_bound(p); if(itr==adds.begin())continue; --itr; res -= itr->second; } return res; }; vector evens; vector odds; rep(i,m){ ll y = in(); ll x = in(); if((y+x)%2){ odds.emplace_back(y,x); }else{ evens.emplace_back(y,x); } } return calc(evens) + calc(odds); } int main(){ println(func()); return 0; }