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
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 123;
int n,m;
int res;
int od,doo,kol;
bool zo[N],ni[N],cz[N];
int z[N],f[N],c[N];
int prefz[N],prefn[N],prefc[N];

int main () {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 1;i <= m;i++){
		cin >> od >> doo >> kol ;
		if(kol == 1){
			z[od]++;
			z[doo+1]--;
		}
		else if (kol == 2) {
			f[od]++;
			f[doo+1]--;
		}
		else {
			c[od]++;
			c[doo+1]--;
		}
	}
	for (int i= 1;i <= n;i++){
		prefz[i] = prefz[i-1] + z[i];
		prefn[i] = prefn[i-1] + f[i];
		prefc[i] = prefc[i-1] + c[i];
	}
	for (int i= 1;i <= n;i++){ 
		if(prefz[i] && prefn[i] && !prefc[i]){
			res++;
		}
	}

	cout  << res << '\n';

return 0;
}