#include template inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; struct mint { ll x; mint(ll x = 0) :x((x%mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator==(const mint a) const { return x == a.x; } bool operator!=(const mint a) const { return x != a.x; } }; istream& operator>>(istream& is, const mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } const int MAX = 710000; long long fac[MAX], finv[MAX], inv[MAX]; //使う前に実行 //pが素数かつp>nが条件 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod%i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main(){ int n, m; cin >> n >> m; COMinit(); mint ans = COM(2*n, n); ans *= 2*n; rep(i, m){ int t, x, y; cin >> t >> x >> y; if(t == 1){ mint now = 1; now *= COM(x+y, x); now *= COM(2*n-x-y-1, n-y); ans -= now; }else{ mint now = 1; now *= COM(x+y, x); now *= COM(2*n-x-y-1, n-x); ans -= now; } } cout << ans << endl; }