MOD = 10 ** 9 + 7 MAX = 4 * 10 ** 5 + 10 # https://tjkendev.github.io/procon-library/python/math/factorial.html から拝借しています。 fact = [1] * (MAX + 1) rfact = [1] * (MAX + 1) r = 1 for i in range(1, MAX + 1): fact[i] = r = r * i % MOD rfact[MAX] = r = pow(fact[MAX], MOD - 2, MOD) for i in range(MAX, 0, -1): rfact[i - 1] = r = r * i % MOD def comb(n, k, error=0): if not 0 <= k <= n: return error return fact[n] * rfact[k] * rfact[n - k] % MOD N, M = map(int, input().split()) ans = comb(N * 2, N) * N * 2 % MOD for _ in range(M): t, x, y = map(int, input().split()) if t == 1: ans -= comb(x + y, x) * comb(N * 2 - x - y - 1, N - y) else: ans -= comb(x + y, x) * comb(N * 2 - x - y - 1, N - x) ans %= MOD print(ans)