using static System.Math; using System; class Modulo { public const int MOD = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) => (int)(BigMul(a, b) % MOD); public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) m_facs[i] = Mul(m_facs[i - 1], i); } public int Fac(int n) => m_facs[n]; public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2)); public int Ncr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } public class Hello { public static int MOD = Modulo.MOD; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var md = new Modulo(n + n); long ans = md.Ncr(n + n, n); ans *= n + n; ans %= MOD; for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var c = int.Parse(line[0]); var x = int.Parse(line[1]); var y = int.Parse(line[2]); long from = md.Ncr(x + y, x); long to = c == 1 ? md.Ncr(2 * n - x - y - 1, n - y) : md.Ncr(2 * n - x - y - 1, n - x); from *= to; from %= MOD; ans -= from; if (ans < 0) ans += MOD; } Console.WriteLine(ans); } }