MOD = 10 ** 9 + 7 table_len = 10 ** 6 + 10 fac = [1, 1] for i in range(2, table_len): fac.append(fac[-1] * i % MOD) finv = [0] * table_len finv[-1] = pow(fac[-1], MOD - 2, MOD) for i in range(table_len-1, 0, -1): finv[i-1] = finv[i] * i % MOD def comb(n, k): if k < 0 or n < 0 or n - k < 0: return 0 return fac[n] * finv[k] % MOD * finv[n - k] % MOD N, M = map(int, input().split()) ans = comb(2 * N, N) * (2 * N) for _ in range(M): t, x, y = map(int, input().split()) if t == 1: ans -= comb(x + y, x) * comb(2 * N - x - y - 1, N - y) % MOD ans %= MOD else: ans -= comb(x + y, x) * comb(2 * N - x - y - 1, N - x) % MOD ans %= MOD print(ans)