// #includes {{{
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

const int mod = 1000000007;
//{{{ modular algebra
template<int mod>
struct Num{
	int v;
	Num(int n):v(n){}
	Num(){}
	operator int() const {return v;}
	operator long long() const {return v;}
	void operator =(int n){v=n;}

	template<class T>
		inline void operator *=(const T &a) {
			v = (v*(long long)a)%mod;
		}
	template<class T>
		inline Num operator *(const T &a) {
			Num n(*this);n*=a;
			return n;
		}
	template<class T>
		inline void operator+=(const T &a){
			v+=(int)a;
			if(v>=mod)v-=mod;
			//	assert(0<=v and v<mod);
		}
	template<class T>
		inline Num operator+(const T &a){
			Num n(*this);n+=a;
			return n;
		}
	inline Num operator -(){
		if(v==0)return v;
		else return Num(mod-v);
	}
	template<class T>
		inline void operator -=(const T &a){
			v-=(int)a;
			if(v<0)v+=mod;
		}
	template<class T>
		inline Num operator -(const T &a){
			Num n(*this);n-=a;
			return n;
		}
#ifdef __GCD_H
	inline Num inv(){
		return invMod(this->v,mod);
	}
	template<class T>
		inline void operator /=(const T &a){
			(*this)*=invMod((int)a,mod);
		}
	template<class T>
		inline Num operator /(const T &a){
			Num n(*this);n/=a;
			return n;
		}
#endif
};

typedef Num<1000000007> U;

template<int mod>
ostream& operator <<(ostream &os,const Num<mod> &n){
	os<<(int)n.v;
	return os;
}

template<int mod>
istream& operator >>(istream &is, Num<mod> &n){
	is>>n.v;
	return is;
}
//}}}

int N,M;

U dp[2][310][310];
vector<vector<vector<int>>> b;

vector<int> next(const vector<int> &s,int c){
	if(s[0]==-1){
		return {0,-1,-1};
	}
	if(c==0){
		return {s[0]+1,s[1],s[2]};
	}else if(c==1){
		return {s[0]+1,s[0],s[2]};
	}else if(c==2){
		return {s[0]+1,s[0],s[1]};
	}else assert(false);
}

int main(){
	cin>>N>>M;
	b.assign(N,vector<vector<int>>());
	REP(i,M){
		int l,r,x;
		cin>>l>>r>>x;
		l--;r--;
		b[r].push_back({l,r,x});
	}
	int from = 0, to = 1;
	memset(dp[from],0,sizeof(dp[from]));
	dp[from][-1+1][-1+1] = 1;
	for(int i=0;i<N;i++){
//		dump(i);
		memset(dp[to],0,sizeof(dp[to]));
		//q -> p -> i-1
		vector<int> ps;
		ps.push_back(-1);
		REP(j,i-1)ps.push_back(j);
		for(auto &p:ps){
			vector<int> qs;
			qs.push_back(-1);
			REP(j,p)qs.push_back(j);
			for(auto &q:qs){
				vector<int> v0 = {i-1,p,q};
				REP(c,3){
					int choice = 1;
					bool flag = false;
					if(v0[c]==-1)flag = true, choice = 3-c;
					auto v = next(v0,c);
					//v[2] -- v[1] -- v[0]
					/*
					cerr<<"from: "<<endl;
					cerr<<" "<<i-1<<" "<<p<<" "<<q<<endl;
					cerr<<" "<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;
					*/
					bool valid = true;
//					dump(b[i].size());
					REP(j,b[i].size()){
						int l = b[i][j][0];
						switch(b[i][j][2]){
						case 1:
							if(not (v[1]<l and l<=v[0]))valid = false;
							break;
						case 2:
							if(not (v[2]<l and l<=v[1]))valid = false;
							break;
						case 3:
							if(not (l<=v[2]))valid = false;
							break;
						default:
							assert(false);
						}
					}
					if(valid){
						dp[to][v[1]+1][v[2]+1] += dp[from][p+1][q+1]*choice;
//						cerr<<"valid: "<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;
					}
					if(flag)break;
				}
//				cerr<<p<<" "<<q<<" "<<dp[from][p+1][q+1]<<",";
			}
		}
//		cerr<<endl;
		swap(from,to);
	}
	U ans(0);
	vector<int> ps;
	ps.push_back(-1);
	REP(j,N-1)ps.push_back(j);
	for(auto &p:ps){
		vector<int> qs;
		qs.push_back(-1);
		REP(j,p)qs.push_back(j);
		for(auto &q:qs){
			ans+=dp[from][p+1][q+1];
//			cerr<<p<<" "<<q<<" "<<dp[from][p+1][q+1]<<",";
		}
//		cerr<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1152