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 <iostream>
#include <vector>
using namespace std;

vector<int> tab[1000007];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin>>n>>m;
	
	for (int i = 0; i < m; i++) {
		int l, r, k;
		cin>>l>>r>>k;
		tab[l].push_back(k);
		tab[r + 1].push_back(-k);
	}
	
	int k1 = 0, k2 = 0, k3 = 0;
	int zielone = 0;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < tab[i].size(); j++) {
			if (tab[i][j] == 1) k1++;
			if (tab[i][j] == -1) k1--;
			
			if (tab[i][j] == 2) k2++;
			if (tab[i][j] == -2) k2--;
			
			if (tab[i][j] == 3) k3++;
			if (tab[i][j] == -3) k3--;
		}
		//cout<<k1<<" "<<k2<<" "<<k3<<endl;
		if (k1 > 0 && k2 > 0 && k3 == 0) {
			zielone++;
		}
	}
	
	cout<<zielone<<"\n";
	return 0;
}