// yuki 1596 Distance Sum in 2D Plane // 2021.8.12 #include typedef long long ll; #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) int in() { // 非負整数の入力 int n = 0; int c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void out(int n) { // 非負整数の表示(出力) int i; char b[30]; if (!n) pc('0'); else { // if (n < 0) pc('-'), n = -n; i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } pc('\n'); } const int mod = (int)1e9+7; int fact[400005], inv[400005], factinv[400005]; int comb(int n, int k) { // if (n < 0 || k < 0) return 0; return (ll)fact[n] * factinv[k] % mod * factinv[n-k] % mod; } // テーブルを作る前処理 void COMinit(int max) { fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i <= max; i++) { fact[i] = (ll)fact[i-1] * i % mod; inv[i] = mod - (ll)inv[mod%i] * (mod/i) % mod; factinv[i] = (ll)factinv[i-1] * inv[i] % mod; } } int main() { int N = in(), N2 = N << 1; COMinit(N2); ll ans = comb(N2, N); ans = (ans * N2) % mod; int M = in(); while (M--) { int t = in(), x = in(), y = in(); ans -= (ll)comb(x+y, y) * comb(N2-x-y-1, N-y-(t-1)) % mod; } ans %= mod; if (ans < 0) ans += mod; out((int)ans); return 0; }