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

using namespace std;


typedef long long LL;


const int MAXN = 1 << 20;


int p[MAXN][4];


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

	int n, m;
	cin >> n >> m;

	while (m--) {
		int l, r, k;
		cin >> l >> r >> k;

		p[l][k]++;
		p[r + 1][k]--;
	}

	int c[4] = {};
	int q = 0;

	for (int i = 1; i <= n; ++i) {
		// cerr << "#" << i << ": ";

		for (int j = 1; j <= 3; ++j) {
			c[j] += p[i][j];
			// cerr << c[j] << " ";
		}

		if (c[3] <= 0 && c[1] > 0 && c[2] > 0)
			q++;

		// cerr << endl;
	}

	cout << q << endl;
}