#include <bits/stdc++.h>
using namespace std;

#define int long long
using ll = long long;
using P = pair<int,int>;

int n,m;

signed main(){
  cin >> n >> m ;
  
  map<int,int> cnt;
  vector<P> p(m);
  for(int i=0;i<m;i++){
    cin >> p[i].first;
    cin >> p[i].second;
    cnt[p[i].first]++;
  }
  
  sort(p.begin(),p.end());
  
  //for(int i=0;i<m;i++){
  //  cout << "i=" << i << ":" << p[i].first << "," << p[i].second << endl;
  //}
  
  vector<int> d(2*m+1,0);
  
  d[m] = 1;
  
  int j = 0;
  map<int,int> manip;
  for(auto it = cnt.begin(); it != cnt.end(); it++){
    int v = it->first;
    // cout << "it->first=" << it->first << endl;
    // int c = it->second;
    manip.clear();
    int j2 = j;
    while( p[j].first == v ){
      int y = p[j].second;    // n座標系
      int y2 = ( y - n ) + m; // m座標系
      if( y2 >= 0 && y2 <= 2*m ){
        manip[y2] = 0;
      }
      j++;
    }
    j = j2;
    while( p[j].first == v ){
      int y = p[j].second;     //
      int y2 = ( y - n ) + m;  // m
      if( y2 >= 0 && y2 <= 2*m && y2-1 >= 0 && y-1>=0 && d[y2-1]==1 ){
        manip[y2]=1;
      }
      if( y2 >= 0 && y2 <= 2*m && y2+1 <=2*m && y+1<=2*n && d[y2+1]==1 ){
        manip[y2]=1;
      }
      j++;
    }
    for(auto x: manip){
      d[x.first] = x.second;
    }
    //for(int j=0;j<2*m+1;j++){
    //  cout << "," << d[j];
    //}
    //cout << endl;
  }
  int res = 0;
  for(int i=0;i<=2*m;i++){
    if(d[i]!=0) res++;
  }
  cout << res << endl;
  
}


#pragma GCC optimize("fast-math")
// begin "cp-lib/boilerplate.hpp"
#include <bits/stdc++.h>

#define _choose(_1, _2, _3, chosen, ...) chosen
#define _rep(i, l, r)     for (int i = l; i < r; ++i)
#define _rep0(i, r)       _rep(i, 0, r)
#define _repr(i, r, l)    for (int i = r; i >= l; --i)
#define _repr0(i, r)      _repr(i, r, 0)
#define rep(...)          _choose(__VA_ARGS__, _rep, _rep0, suppress_warning)(__VA_ARGS__)
#define repr(...)         _choose(__VA_ARGS__, _repr, _repr0, suppress_warning)(__VA_ARGS__)
#define all(a)      ::begin(a),::end(a)
#define sz(c)       int(::size(c))
#define trav(a, b)  for(auto& a : b)

using namespace std;

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

[[maybe_unused]] static constexpr int INF = int(1e9 + 5);
[[maybe_unused]] static constexpr ll INFL = ll(INF) * INF;
[[maybe_unused]] static mt19937 rng(u32(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()));

namespace cp_lib {}
// end "cp-lib/boilerplate.hpp"

using namespace cp_lib;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    map<int, int> m;
    int n; cin >> n;
    rep(_, n) {
        int ai; cin >> ai;
        m[ai]++;
    }

    ll ans = 0;
    for (auto& [a1, c1] : m) {
        for (auto& [a2, c2] : m) {
            if (a1 <= a2)
                continue;
            ans += ll(c1) * c2 * (a2 - a1) * (a2 - a1);
        }
    }

    cout << ans << '\n';
}
