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
//Marcin Wróbel
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i = (int)(x); i < (int)(y); ++i)
#define FORE(i,x,y) for(int i = (int)(x); i <= (int)(y); ++i)
#define FORD(i,x,y) for(int i = (int)(x); i >= (int)(y); --i)
#define PB push_back
typedef long long ll;
typedef pair<int,int> pii;

const int MAXN=1e6+7;

int n, m;

int a[MAXN][4];
int b[4];
int ans = 0;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);

    cin >> n >> m;

    while (m--) {
        int l,r,k;
        cin >> l >> r >> k;
        ++a[l][k];
        --a[r+1][k];
    }

    FORE(i,1,n) {
        b[1] += a[i][1];
        b[2] += a[i][2];
        b[3] += a[i][3];
        if(b[1] > 0 && b[2] > 0 && b[3] == 0 ) ++ans;
    }
    cout<< ans <<"\n";
    return 0;
}