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
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1<<20;
int t[2*MAX][3];
void update(int u,int v,int c,int id){
  for (u+=MAX,v+=MAX+1;u<v;u>>=1,v>>=1){
    if (u&1)t[u++][id]+=c;
    if (v&1)t[--v][id]+=c;
  }
}

int query(int u,int id){
  int sum=0;
  for (u+=MAX;u>0;u>>=1){
    sum+=t[u][id];
  }
  return sum;
}
int32_t main(){
  BOOST;
  int n,q;
  cin>>n>>q;
  for (int z=0;z<q;z++){
    int l,r,type;
    cin>>l>>r>>type;
    type--;
    update(l,r,1,type);   
  }
  int ans=0;
  for (int i=1;i<=n;i++){
    if (query(i,0) && query(i,1) && !query(i,2)){
      ans++;
    }
  } 
  cout<<ans;
  return 0; 
}