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

int main() {
	int N;
	cin >> N;
	vector<int> t(N);
	vector<double> l(N), r(N);
	for (int i = 0; i < N; i++) scanf("%d %lf %lf", &t[i], &l[i], &r[i]);

	int Ans = 0;
	for (int i = 0; i < N - 1; i++) {
		double l1, r1;
		if (t[i] == 1) l1 = l[i], r1 = r[i]; 
		else if (t[i] == 2) l1 = l[i], r1 = r[i] - 0.1;
		else if (t[i] == 3) l1 = l[i] + 0.1, r1 = r[i]; 
		else l1 = l[i] + 0.1, r1 = r[i] - 0.1; 

		for (int j = i + 1; j < N; j++) {
			double l2, r2;
			if (t[j] == 1) l2 = l[j], r2 = r[j]; 
			else if (t[j] == 2) l2 = l[j], r2 = r[j] - 0.1; 
			else if (t[j] == 3) l2 = l[j] + 0.1, r2 = r[j]; 
			else l2 = l[j] + 0.1, r2 = r[j] - 0.1;

			if (r1 < l2 || r2 < l1) continue;
			Ans++;
		}
	}

	cout << Ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;

#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(12) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
inline void ose(string x){ os(x); oe(); }
inline void maxin(ll &a, ll b){ a=max(a,b); }
inline void minin(ll &a, ll b){ a=min(a,b); }


int main(){
    ll N=ii(), M=ii();
    if(N==M){
        oie(0);
        return 0;
    }
    if(M==0){
        oie(1);
        return 0;
    }
    vector<ll> A;
    REP(i,0,M){
        A.push_back(ii());
    }
    sort(A.begin(), A.end());
    ll cur=1;
    ll k=112345678901;
    vector<ll> B;
    for(ll a:A){
        if(a>cur){
            B.push_back(a-cur);
            minin(k,a-cur);
        }
        cur=a+1;
    }
    if(N>=cur){
        B.push_back(N-cur+1);
        minin(k,N-cur+1);
    }
    ll ret=0;
    for(ll b:B){
        ret+=b/k;
        if(b%k>0){ret++;}
    }
    oie(ret);

    return 0;
}
