#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF=0x7fffffff;
const int eps=1e-7;
const long long mod=1e9+7;
const int maxn=210000;
int n,m,x[maxn],y[maxn];
int main(void)
{
    cin>>n>>m;
    map<int,set<int>>mp;
    for(int i=0;i<m;++i)cin>>x[i]>>y[i],mp[x[i]].insert(y[i]);
    set<int>ans;
    ans.insert(n);
    for(auto it=mp.begin();it!=mp.end();++it)
    {
        set<int>temp;
        for(auto pos:it->second)
        {
            temp.insert(pos-1);
            temp.insert(pos+1);
            temp.insert(pos);
        }
        set<int>pass;
        for(auto pos:temp)
        {
            if(ans.count(pos-1)&&it->second.count(pos)||ans.count(pos)&&!it->second.count(pos)||ans.count(pos+1)&&it->second.count(pos))pass.insert(pos);
        }
        for(auto pos:temp)
        {
            if(ans.count(pos))ans.erase(pos);
        }
        for(auto pos:pass)
        {
            ans.insert(pos);
        }
    }
    cout<<ans.size()<<endl;
    return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int kei = 0;
	ll kei2 = 0;
	rep(i, N) {
		int a = getint();
		kei += a;
		kei2 += a * a;
	}

	printf("%lld", kei2 * N - (ll)kei * kei);

	Would you please return 0;
}