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

const int MxNM = 1e6+3;
vector<int> puszki[MxNM+1];
int n, m;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for (int i=0; i<m; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		for (int j=a; j<=b; j++)
			puszki[j].push_back(c);
	}

	int ans = 0;
	for (int i=1; i<=n; i++)
	{
		bool y=0, b=0, r=0;
		for (auto j : puszki[i])
		{
			if (j == 1) y = 1;
			if (j == 2) b = 1;
			if (j == 3) r = 1;
		}
		if (y && b && !r)
			ans++;
	}

	cout << ans << "\n";

	return 0;
}