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
#include<iostream>

using namespace std;

const int MAX_N = 1000007;
const int MAX_K = 5;

int kol[MAX_N][MAX_K];
int val[MAX_K];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, l, r, k, result = 0;
	cin >> n >> m;
	while(m--) {
		cin >> l >> r >> k;
		kol[l][k]++;
		kol[r+1][k]--;
	}
	for(int i = 1; i <= n; i++) {
		val[1] += kol[i][1];
		val[2] += kol[i][2];
		val[3] += kol[i][3];
		if(val[1] && val[2] && !val[3]) result++;
	}
	cout << result << "\n";
	return 0;
}