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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>

void kolorowanie(int kolory[], int j, int k)
{
    switch (kolory[j])
    {
    case 0:
        switch (k)
        {
        case 1:
            kolory[j] = 1;
            break;
        case 2:
            kolory[j] = 2;
            break;
        case 3:
            kolory[j] = 3;
            break;
        }
        break;
    case 1:
        switch (k)
        {
        case 2:
            kolory[j] = 4;
            break;
        case 3:
            kolory[j] = 5;
            break;
        }
        break;
    case 2:
        switch (k)
        {
        case 1:
            kolory[j] = 4;
            break;
        case 3:
            kolory[j] = 6;
            break;
        }
        break;
    case 4:
        if (k == 3)
            kolory[j] = 7;
        break;
    }
}

int main()
{
    int n = 0;
    int m = 0;

    std::cin >> n;
    std::cin >> m;

    int l = 0;
    int r = 0;
    int k = 0;

    int counter = 0;

    int* kolory = new int[n];
    for (int i = 0; i < n; i++)
    {
        kolory[i] = 0;
    }

    for (int i = 0; i < m; i++)
    {
        std::cin >> l;
        std::cin >> r;
        std::cin >> k;

        for (int j = l; j <= r; j++)
        {
            kolorowanie(kolory, j, k);
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if (kolory[i] == 4)
            counter++;
    }
    std::cout << counter;



    delete[] kolory;
    return 0;
}