#include using namespace std; template void compress(vector &a) { auto sorted{a}; sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end()); for (auto &&x : a) { x = lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin(); } } int main() { int64_t n, m; cin >> n >> m; vector l(m), r(m); for (int i = 0; i < m; i++) { int64_t x, y; cin >> x >> y; l.at(i) = x + y; r.at(i) = x - y; } sort(l.begin(), l.end()); l.erase(unique(l.begin(), l.end()), l.end()); sort(r.begin(), r.end()); r.erase(unique(r.begin(), r.end()), r.end()); int64_t ans = 0; for (auto &&x : l) { ans += min(x - 1, 2 * n + 1 - x); } for (auto &&x : r) { ans += min(x + n, n - x); } vector merged0, merged1; int l0 = 0, l1 = 0; for (auto &&x : l) { if (x % 2 == 0) { merged0.emplace_back(x); l0++; } else { merged1.emplace_back(x); l1++; } } for (auto &&x : r) { if (x % 2 == 0) { merged0.emplace_back(2 + abs(x)); merged0.emplace_back(2 * n - abs(x) + 1); } else { merged1.emplace_back(2 + abs(x)); merged1.emplace_back(2 * n - abs(x) + 1); } } compress(merged0); compress(merged1); vector s0(100001), s1(100001); for (int i = 0; i < l0; i++) { s0.at(merged0.at(i) + 1)++; } for (int i = 0; i < l1; i++) { s1.at(merged1.at(i) + 1)++; } for (int i = 0; i < 100000; i++) { s0.at(i + 1) += s0.at(i); s1.at(i + 1) += s1.at(i); } int r0 = (merged0.size() - l0) / 2; int r1 = (merged1.size() - l1) / 2; for (int i = 0; i < r0; i++) { int a = merged0.at(l0 + 2 * i); int b = merged0.at(l0 + 2 * i + 1); ans += s0.at(a) - s0.at(b); } for (int i = 0; i < r1; i++) { int a = merged1.at(l1 + 2 * i); int b = merged1.at(l1 + 2 * i + 1); ans += s1.at(a) - s1.at(b); } cout << ans << endl; return 0; }