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

using namespace std;

const int N = 1 << 20;

int color[N << 1];

void modify(int l, int r, int k){
    color[l += N] |= k, color[r += N] |= k;
    while(l >> 1 != r >> 1){
        if(l % 2 == 0)  color[l + 1] |= k;
        if(r % 2 == 1)  color[r - 1] |= k;
        l >>= 1, r >>= 1;
    }
}

int query(int u){
    int ans = color[u += N];
    while(u >>= 1){
        ans |= color[u];
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m, ans = 0;   cin >> n >> m;
    for(int i = 0; i < m; i++){
        int l, r, k;    cin >> l >> r >> k;
        if(k == 3)  k = 4;  
        modify(l - 1, r - 1, k);
    }
    for(int i = 0; i < n; i++){
        ans += (query(i) == 3);
    }
    cout << ans << "\n";
}