#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
using ll = long long;
//#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
using namespace std;


ll n;
ll sum = 0;
ll m;
ll k;
ll minV;

int main() {
    vector<ll> v;
    cin >> n >> m;
    rep(i,m) {
    	cin >> k;
    	v.push_back(k);
    }
    if (m == 0) {
        cout << 1;

    	return 0;
    }

    sort(v.begin(), v.end());
    if(v[v.size()-1] != n) v.push_back(n+1);

    minV = 1000001000;
    if (v[0] - 1 < minV && v[0] != 1) minV = v[0] - 1;
    for (int i = 1; i < v.size(); i++)
    {
        if (v[i] - v[i-1] -1 < minV && (v[i] - v[i-1] -1) != 0) minV = v[i] - v[i-1] -1;
    }
    if (v[0] != 0){
        if ((v[0] - 1) % minV == 0){
        	sum += (v[0] - 1) / minV;
        }
        else{
        	sum += (v[0] - 1) / minV + 1;
        }
    }

    if (minV == 1000001000) {
        cout << 0;

    	return 0;
    }
    for (int i = 1; i < v.size(); i++)
    {
        if((v[i] - v[i-1]-1) % minV == 0){
        	sum += (v[i] - v[i-1] -1) / minV;
        }
        else{
        	sum += (v[i] - v[i-1]-1) / minV + 1;
        }
    }

    cout << sum;

	return 0;
}
// Problem: C - Many Segments
// Contest: AtCoder - AtCoder Beginner Contest 207
// URL: https://atcoder.jp/contests/abc207/tasks/abc207_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define ff first
#define ss second
#define vp vector <pair<int,int>>
#define vpp vector <pair<int,pair<int,int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v),0)
#define fs(it,a) for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue <int,vector <int>> 
#define pqmin priority_queue <int,vector <int>,greater<int>> 
#define dq deque <int>
#define umi unordered_map<int,int>
#define ums unordered_map<string,int>
#define sp(x,y) fixed << setprecision(y) << x
#define out(r,x) cout<<"Case #"<<r<<": "<<x<<ee;
#define all(x) x.begin(),x.end()
#define f(x,y,z) for(x=y;x<z;x++)
#define si size()
#define countdigit(x) floor(log10(x) +1)
#define M 1000000007
#define Z 998244353 
#define fill(arr,x) memset(arr,x,sizeof(arr))
//Use (k%M+m)%m always where k is any no
#define PI 3.1415926535
#define lcm(a,b)  a*b/(__gcd(a,b))
typedef tree<int, null_type, less<int>, rb_tree_tag, 
 tree_order_statistics_node_update> pdbs; 
// // null for set,mapped_type for map; 
// //less for assending greater for descending
//ceil(a/b)=(a+b-1)/b
// v.si-1 can never be negative
#define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
#define ee "\n"
#define re return 
 
 
//Author Rahul Sannigrahi
 
vector<int> take(int n)
{
    int i,j;
    vi v;
    f(i,0,n)
    {
        cin>>j;
        v.pb(j);
    }
    return v;
}
 
int power(int x,int y)
{
    int res=1;
    
    while(y>0)
    {
       if(y&1)
       res=((res%M)*(x%M))%M;
       
       y=y>>1;
       x=((x%M)*(x%M))%M;
    }
    re res;
} 
 
bool sortinrev(const pair<int,int> &a,  //desc of vp
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
}
 
 
 
 
 
void show(vector<int>v)
{
    int i;
    for(i=0;i<v.si;i++)
    {
     cout<<v[i]<<" ";   
    }
    cout<<ee;
}
 
int gk=1;
int ks=0;
 
int decode()
{
int i,j,n,k;
cin>>n;
double l,r;
vector<pair<double,double>> v;
f(i,0,n)
{
	cin>>k>>l>>r;
	if(k==1)
	v.pb({l,r});
	else if(k==2)
	v.pb({l,r-.01});
	else if(k==3)
	v.pb({l+.01,r});
	else
	v.pb({l+.01,r-.01});
}

int ans=0;
 sort(all(v));
 // f(i,0,n)
 // cout<<v[i].ff<<" "<<v[i].ss<<endl;
f(i,0,n)
{
	f(j,i+1,n)
	{
		if((v[j].ff>=v[i].ff and v[j].ff<=v[i].ss)||(v[j].ss>=v[i].ff and v[j].ss<=v[i].ss))
		{
		ans++;
		// cout<<v[j].ff<<ee;
		}
	}
}
cout<<ans<<endl;
   re 0;
}
 
 
 
int32_t main()
{
    IOS
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif 
    
    int t=1;
       // cin>>t;
    while(t--)
    {
      if (ks) 
        {
            cout << "Case #" << gk << ": "; 
         gk++;
        }
    decode();
    }
    return 0;
}