import java.util.Scanner; public class Main { static long[] frac = null; static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); int M = Integer.parseInt(sc.next()); int[] t = new int[M]; int[] x = new int[M]; int[] y = new int[M]; for ( int i = 0 ; i < M ; i++ ) { t[i] = Integer.parseInt(sc.next()); x[i] = Integer.parseInt(sc.next()); y[i] = Integer.parseInt(sc.next()); } sc.close(); frac = new long[2 * N + 2]; rec(2 * N + 1); long ans = (comb(2 * N, N) * 2 * N) % MOD; for ( int i = 0 ; i < M ; i++ ) { if ( t[i] == 1 ) { long a1 = comb(x[i] + y[i], x[i]); long a2 = comb(2 * N - x[i] - y[i] - 1, N - x[i] - 1); ans = (ans - (a1 * a2) % MOD + MOD) % MOD; } else { long a1 = comb(x[i] + y[i], x[i]); long a2 = comb(2 * N - x[i] - y[i] - 1, N - x[i]); ans = (ans - (a1 * a2) % MOD + MOD) % MOD; } } System.out.println(ans); } static long comb(int n, int a) { long ret = frac[n]; long x = modInv(frac[a], MOD); long y = modInv(frac[n - a], MOD); return (((ret * x) % MOD) * y) % MOD; } static long rec(int a) { if ( a <= 0 ) { frac[a] = 1; return 1; } long x = (((long) a) * ((long)rec(a - 1))) % MOD; frac[a] = x; return x; } static long[] xgcd(long a, long b) { long x0 = 1; long y0 = 0; long x1 = 0; long y1 = 1; while ( b != 0 ) { long q = a / b; long tmp = b; b = a % b; a = tmp; tmp = x1; x1 = x0 - q * x1; x0 = tmp; tmp = y1; y1 = y0 - q * y1; y0 = tmp; } return new long[] {a, x0, y0}; } static long modInv(long a, long p) { long[] xgcd = xgcd(a, p); return (xgcd[1] + p) % p; } }