MOD = 10 ** 9 + 7 N, M = map(int, input().split()) Kaijo = [1] * (N + N + 1) KaijoInv = [1] * (N + N + 1) for i in range(1, N + N + 1): Kaijo[i] = Kaijo[i - 1] * i % MOD KaijoInv[i] = pow(Kaijo[i], MOD - 2, MOD) nCr = lambda n, r: Kaijo[n] * KaijoInv[n - r] % MOD * KaijoInv[r] % MOD Ans = nCr(N + N, N) * 2 * N % MOD for _ in range(M): T, X, Y = map(int, input().split()) if T == 1: Ans -= nCr(X + Y, X) * nCr(N - X - 1 + N - Y, N - Y) % MOD if T == 2: Ans -= nCr(X + Y, X) * nCr(N - X + N - Y - 1, N - X) % MOD Ans %= MOD print(Ans)