1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
using namespace __gnu_pbds;

// replace ll  with pair if multiset needed
typedef tree<pair<ll,ll>, null_type, greater<pair<ll,ll> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;

// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)

//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

const int SIZE = 1e6 + 6;

int tab[4][SIZE];

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

	int n,m; cin >> n >> m;
	
	for(int i = 1; i <= m; i++){
		int l,r,k; cin >> l >> r >> k;
		tab[k][l]++,tab[k][r+1]--;
	}

	int licz1 = 0, licz2 = 0, licz3 = 0,ans = 0;	
	for(int i = 1; i <= n; i++){
		licz1 += tab[1][i], licz2 += tab[2][i], licz3 += tab[3][i];
		if(licz1 > 0 && licz2 > 0 && licz3 == 0) ans++;
	}
	
	cout << ans << "\n";
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


	return 0;
}