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
//  Mieszanie kolorow
//  Sebastian Mroz

#include<bits/stdc++.h>
#define ll long long 
#define pp pair<int, int>
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int maxN = 1000007;
int T[maxN][4];
int C[4];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, m, a, b, c, wynik = 0;
	cin >> n >> m;
	while(m--){
		cin >> a >> b >> c;
		++T[a][c];
		--T[b + 1][c];
	}
	for(int i = 1; i <= n; ++i){
		C[1] += T[i][1];
		C[2] += T[i][2];
		C[3] += T[i][3];
		if(C[1] != 0 && C[2] != 0 && C[3] == 0) ++wynik;
		/*
		if(C[1] == 0 && C[2] == 0 && C[3] == 0) cout << "White\n";
		if(C[1] != 0 && C[2] == 0 && C[3] == 0) cout << "Yellow\n";
		if(C[1] == 0 && C[2] != 0 && C[3] == 0) cout << "Blue\n";
		if(C[1] == 0 && C[2] == 0 && C[3] != 0) cout << "Red\n";
		if(C[1] != 0 && C[2] != 0 && C[3] == 0) cout << "Green\n";
		if(C[1] != 0 && C[2] == 0 && C[3] != 0) cout << "Orange\n";
		if(C[1] == 0 && C[2] != 0 && C[3] != 0) cout << "Purple\n";
		if(C[1] != 0 && C[2] != 0 && C[3] != 0) cout << "Brown\n";
		*/
	}
	
	cout << wynik << "\n";
	
	return 0;
}