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
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 7;

int n, m;
int pref[N][3];

int main () {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int l, r, k;
		scanf("%d %d %d", &l, &r, &k);
		
		pref[l][k - 1]++;
		pref[r + 1][k - 1]--;
	}
	
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int t = 0; t < 3; ++t)
			pref[i][t] += pref[i - 1][t];
		
		if (pref[i][0] > 0 && pref[i][1] > 0 && pref[i][2] == 0)
			++ans;
	}
	
	printf("%d\n", ans);
	return 0;
}