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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int BASE = 1 << 20;
int tree[2 * BASE + 9];
int n, m;

void add(int v, int sb, int se, int rb, int re, int val)
{
    if (se < sb) return;
    if (se < rb || re < sb) return;

    if (rb <= sb && se <= re)
    {
        tree[v] |= val;
        return;
    }

    int mid = (sb + se) / 2;
    add(2 * v, sb, mid, rb, re, val);
    add(2 * v + 1, mid + 1, se, rb, re, val);
}

void push_down()
{
    for (int v = 1; v < BASE; v++)
    {
        tree[2 * v] |= tree[v];
        tree[2 * v + 1] |= tree[v];
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n >> m;
    int l, r, x;
    while (m--)
    {
        cin >> l >> r >> x;

        x--;
        add(1, 0, BASE - 1, l, r, (1 << x));
    }

    push_down();

    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (tree[BASE + i] == 3) ans++;
    }

    cout << ans << "\n";
}