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 <stdio.h>
#include <strings.h>
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#include <tuple>
#include <cstdio>

using namespace std;

int paints[1000010][3] = {0};

int main() {
    int m,n;
    //cin>>n>>m;
    scanf("%d %d\n", &n, &m);
    
    vector< tuple<int,int,int> > v;
    for (int i=0; i<m; ++i){
        int l, r, k;
        //cin>>l>>r>>k;
        scanf("%d %d %d\n", &l, &r, &k);
        v.push_back( make_tuple(l-1, +1, k) );
        v.push_back( make_tuple(r, -1, k) );               
    }
    sort(v.begin(), v.end());

    int pos=0;
    for (auto [p,sign,k]: v) {        
        int startpos=pos;
        while(pos<p) {
            pos++;
            paints[pos][0] = paints[startpos][0];    
            paints[pos][1] = paints[startpos][1];    
            paints[pos][2] = paints[startpos][2];            
        }
        paints[pos][k-1] += sign;
    }
    
    long count = 0;
    for (int i=0; i<=n; ++i) {
        if (paints[i][0]>0 && paints[i][1]>0 && paints[i][2]==0) count++;
    }
    
    cout<<count<<endl;
    return 0;
}