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
 94
 95
 96
 97
 98
 99
100
#include <bits/stdc++.h>
using namespace std;
const int baza = 1048576;
int n,m;
int d1[2*baza];
int d2[2*baza];
int d3[2*baza];

int czytaj1 (int poz){
poz=poz+baza-1;
int wynik=0;
while(poz>0){
    wynik=wynik+d1[poz];
    poz=poz/2;
}
return wynik;
}
int czytaj2 (int poz){
poz=poz+baza-1;
int wynik=0;
while(poz>0){
    wynik=wynik+d2[poz];
    poz=poz/2;
}
return wynik;
}
int czytaj3 (int poz){
poz=poz+baza-1;
int wynik=0;
while(poz>0){
    wynik=wynik+d3[poz];
    poz=poz/2;
}
return wynik;
}
void update1(int targetleft, int targetright, int currentleft, int currentright, int poz, int war){
if(targetleft<=currentleft&&currentright<=targetright){
    d1[poz]=d1[poz]+war;
    return;
}
if(targetleft<=(currentleft+currentright)/2){
    update1(targetleft,targetright, currentleft, (currentleft+currentright)/2,poz*2,war);
}
if((currentleft+currentright)/2<targetright){
    update1(targetleft,targetright,(currentleft+currentright)/2 +1,currentright,poz*2+1,war);
}
}
void update2(int targetleft, int targetright, int currentleft, int currentright, int poz, int war){
if(targetleft<=currentleft&&currentright<=targetright){
    d2[poz]=d2[poz]+war;
    return;
}
if(targetleft<=(currentleft+currentright)/2){
    update2(targetleft,targetright, currentleft, (currentleft+currentright)/2,poz*2,war);
}
if((currentleft+currentright)/2<targetright){
    update2(targetleft,targetright,(currentleft+currentright)/2 +1,currentright,poz*2+1,war);
}
}
void update3(int targetleft, int targetright, int currentleft, int currentright, int poz, int war){
if(targetleft<=currentleft&&currentright<=targetright){
    d3[poz]=d3[poz]+war;
    return;
}
if(targetleft<=(currentleft+currentright)/2){
    update3(targetleft,targetright, currentleft, (currentleft+currentright)/2,poz*2,war);
}
if((currentleft+currentright)/2<targetright){
    update3(targetleft,targetright,(currentleft+currentright)/2 +1,currentright,poz*2+1,war);
}
}
int a,b,c;
int x,y,z;
int t[9];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
cin>>n>>m;

for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    if(c==1)update1(baza+a-1,baza+b-1,baza,2*baza-1,1,1);
    if(c==2)update2(baza+a-1,baza+b-1,baza,2*baza-1,1,1);
    if(c==3)update3(baza+a-1,baza+b-1,baza,2*baza-1,1,1);
}
int wynik=0;
for(int i=1;i<=n;i++){
    x=czytaj1(i);
    y=czytaj2(i);
    z=czytaj3(i);

    if(x!=0&&y!=0&&z==0)wynik++;

}

cout<<wynik;



}