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

const int N = ((int)(1e6))+50;

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

int main(){
	ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 );
	cin>>n>>m;
	int t1,t2,t3;
	for (int i = 0; i < m; i++){
		cin>>t1>>t2>>t3;
		prefs[t1][t3-1] += 1;
		prefs[t2+1][t3-1] -= 1;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		prefs[i][0] = prefs[i-1][0] + prefs[i][0];
		prefs[i][1] = prefs[i-1][1] + prefs[i][1];
		prefs[i][2] = prefs[i-1][2] + prefs[i][2];
	}
	for (int i = 1; i <= n; i++){
		if( ( prefs[i][0] > 0 ) && ( prefs[i][1] > 0 ) && ( prefs[i][2] == 0 ) ) ans++; 
	}
	cout<<ans;
	return 0;
}