#include #include #include #include #include #include #include #include #include #include #include #include #include #define flush fflush(stdout) #define endl '\n' #define all(v) v.begin(), v.end() #define pf(dans) printf("%.12lf", dans) #define pfn(dans) pf(dans); cout << endl; using namespace std; //using namespace atcoder; typedef long long ll; typedef pair P; typedef pair Pl; const int mod1 = (int)1e9 + 7, mod2 = (int)998244353; const int INF = (int)1e9 + 10; const ll LINF = (ll)1e18 + 10; const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1}; #define rep0(i, n) for (i = 0; i < n; i++) #define rep1(i, a, b) for (i = a; i < b; i++) #define reprev(i, n) for (i = n - 1; i >= 0; i--) template T my_abs(T x){ return (x >= 0)? x : -x; } template void chmax(T &a, T b){ a = max(a, b); } template void chmin(T &a, T b){ a = min(a, b); } ll gcd(ll a, ll b){ if (a > b) return gcd(b, a); if (a == 0) return b; return gcd(b % a, a); } bool incld_bit(ll bit, int i){ return ((bit>>i) & 1) == 1; } // -------------------------------------------------------------------------------- #define N 200007 #define commod mod1 ll fac[N], inv[N], finv[N]; void cominit(int n) { int i; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (i = 2; i < n + 2; i++) { fac[i] = fac[i - 1] * i % commod; inv[i] = commod - inv[commod % i] * (commod / i) % commod; finv[i] = finv[i - 1] * inv[i] % commod; } return; } ll com(int n, int r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; if (r == 0 || r == n) return 1; return (fac[n] * finv[r]) % commod * finv[n - r] % commod; } int main(void){ int i, j; int n, m; int t, x, y; ll otoku; otoku = 0; cin >> n >> m; cominit(n * 2); rep0(i, m){ cin >> t >> x >> y; if (t == 1){ otoku = (otoku + com(x + y, x) * com(n * 2 - x - y - 1, n - x - 1) % mod1) % mod1; }else{ otoku = (otoku + com(x + y, x) * com(n * 2 - x - y - 1, n - y - 1) % mod1) % mod1; } } ll ans; ans = (ll)n * 2 * com(n * 2, n) % mod1; ans = (ans + mod1 - otoku) % mod1; cout << ans << endl; return 0; }