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;
#define fi first
#define se second
#define pb push_back
typedef pair <int, int> pii;
typedef long long ll;
typedef double db;

const int N = 1e6;

int n, m, out, x, y, z;
int a[N + 5], b[N + 5], c[N + 5];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	
	cin >> n >> m;
	while(m --){
		cin >> x >> y >> z;
		if(z == 1){
			a[x] ++;
			a[y + 1] --;
		}
		if(z == 2){
			b[x] ++;
			b[y + 1] --;
		}
		if(z == 3){
			c[x] ++;
			c[y + 1] --;
		}
	}
	for(int i=1; i<=n; i++){
		a[i] += a[i - 1];
		b[i] += b[i - 1];
		c[i] += c[i - 1];
	}
	for(int i=1; i<=n; i++){
		out += (a[i] > 0 and b[i] > 0 and c[i] == 0);	
	}
	cout << out << "\n";
	
	return 0;
}