#include<bits/stdc++.h>
        using namespace std;
        #define ll long long
        #define llu unsigned long long
        #define ld double
        #define llu unsigned long long
        #define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
        #define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
        #define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
        #define pi acos(-1) 
        #define mk make_pair
        #define pa pair<ll,ll>
        #define lf else if
        #define IL inline
        #define sqr(x)      ((x)*(x))
        #define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
        #define Add(x,y)    ((x)=((x)+(y))%mod)
        #define E(x)        return writeln(x),0
        #define LL			(long long)
        #define p(x)        printf("~%lld~\n",LL(x))
        #define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
        #define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
        #define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
        #define f_in(x)     freopen(x".in","r",stdin)
        #define f_out(x)    freopen(x".out","w",stdout)
        #define open(x)     f_in(x),f_out(x)
        #define fi first
        #define se second
        #define GuYue		puts("\nGuYueNa________________________________________________________________________________")
        #define y1			fafa____
        typedef complex<double> E;
        namespace SHENZHEBEI{
        #ifdef LOCAL
            struct _{_(){freopen("cf.in","r",stdin);}}_; 
        #endif 
        #define NEG 1
            static const int GYN=2333333;
            char SZB[GYN],*S=SZB,*T=SZB;
            inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
        #if NEG
            inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
            inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
        #else
            inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
            inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
        #endif
            inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
            inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
        	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);puts("");}
        	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);puts("");}
        	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);puts("");}
        	void writeln(ll x){write(x),puts("");}
        }using namespace SHENZHEBEI;
        const ll mod=1e9+7,N=310;
        vector<pa>g[N];
        ll f[N][N][N],l[N],r[N],x[N],n,m,answ;
        int main(){
        	n=read(),m=read();
        	For(i,1,m){
        		l[i]=read(),r[i]=read(),x[i]=read();
        		g[r[i]].push_back(mk(l[i],x[i]));
        	}f[0][0][0]=1;
        	For(i,1,n)For(col1,0,i-1)For(col2,0,i-1)if (f[i-1][col1][col2]){
        		if (col1&&col2&&(col1==col2))continue;
        		For(j,1,3){
        			ll now1=col1,now2=col2,now3=i-1;
        			if (j==1)now1=i;
        			if (j==2)now2=i;
        			if (j==3)now3=i;
        			ll x=now1,y=now2,z=now3;
        			if (x>z)swap(x,z);
        			if (y>z)swap(y,z);
        			if (x>y)swap(x,y);
        			bool frog=1;
        			rep(k,0,g[i].size()){
        				if (g[i][k].se==1){
        					if (y>=g[i][k].fi)	frog=0;
        				}
        				if (g[i][k].se==2){
        					if (x>=g[i][k].fi)	frog=0;
        					if (y<g[i][k].fi)	frog=0;
        				}
        				if (g[i][k].se==3){
        					if (x<g[i][k].fi)	frog=0;
        				}
        			}if (frog){
        				if (j==1)Add(f[i][now2][now3],f[i-1][col1][col2]);
        				if (j==2)Add(f[i][now1][now3],f[i-1][col1][col2]);
        				if (j==3)Add(f[i][now1][now2],f[i-1][col1][col2]);
        			}
        		}
        	}For(i,0,n)For(j,0,n)Add(answ,f[n][i][j]);
        	writeln(answ);
        }
        /*
        [				]
        对每个点,存最右边的1,最右边的2,最右边的3。。
        对于每个右端点判断是否合法。。
        	[2,5]	2
        	[4,5]	1
        	[1,5]	3
        	>=1	有3个。。
        	>=2	有2个。。
        	>=4	有1个。。
        f[i][1]
        f[i][2]
        f[i][3]
        */

Measured memory_bytes: 227584