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
65
66
67
68
69
70
71
72
73
74
75
//Elżbieta Łabaj

#include <bits/stdc++.h>

using namespace std;

constexpr int LIMIT = 1e6 + 3;
short cans[LIMIT];



void mix_yellow(int i) {
    int c = cans[i];
    if (c == 0) cans[i] = 1;
    else if (c == 2) cans[i] = 4;
    else if (c == 3) cans[i] = 5;
    else if (c == 6) cans[i] = 7;
}

void mix_blue(int i) {
    int c = cans[i];
    if (c == 0) cans[i] = 2;
    else if (c == 1) cans[i] = 4;
    else if (c == 3) cans[i] = 6;
    else if (c == 5) cans[i] = 7;
}

void mix_red(int i) {
    int c = cans[i];
    if (c == 0) cans[i] = 3;
    else if (c == 1) cans[i] = 5;
    else if (c == 2) cans[i] = 6;
    else if (c == 4) cans[i] = 7;
}

void mix(int i, int color) {
    if (color == 1) mix_yellow(i);
    else if (color == 2) mix_blue(i);
    else mix_red(i);
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cout.tie(nullptr);

    int cans_cnt, actions;
    cin >> cans_cnt >> actions;

    while (actions--) {
        int l, r, color;
        cin >> l >> r >> color;
        for (int i = l; i <= r; i++) mix(i, color);
    }

    int green_cnt = 0;
    for (int i = 1; i <= cans_cnt; i++) {
        if (cans[i] == 4) green_cnt++;
    }

    cout << green_cnt << '\n';

    return 0;
}

/*
0 - biały
1 - żółty
2 - niebieski
3 - czerwony
4 - zielony (1 + 2)
5 - pomarańczowy (1 + 3)
6 - fioletowy (2 + 3)
7 - brązowy (1 + 2 + 3)
*/