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
49
50
51
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using Ppi = pair<Pii, int>;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define rep(i,b,e) for(int i=(b); i < (e); i++)
#define each(a,x) for(auto& a : (x))
#define all(x) (x).begin(),(x).end()
#define sz(x) int((x).size())
#define endl '\n'

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> cnt(4, vector<int>(n+2));
    for (int i = 0; i < m; i++) {
        int l, r, k;
        cin >> l >> r >> k;
        cnt[k][l]++;
        cnt[k][r+1]--;
    }
    for (int t = 1; t <= 3; t++) {
        for (int i = 1; i <= n; i++) {
            cnt[t][i] += cnt[t][i-1];
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (cnt[1][i] > 0 && cnt[2][i] > 0 && cnt[3][i] == 0) {
            res++;
        }
    }
    cout << res << endl;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(12);
    int z = 1;
    //cin >> z;
    for (int i = 0; i < z; i++) {
        //cout << "Case #" << i+1 << ": ";
        solve();
    }
}