#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """2 1 # 1 0 0 # """ # sys.stdin = io.StringIO(_INPUT) INF = 10**10 MOD = 1000000007 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 def comb(n, r): r = min(r, n - r) return (fact[n] * factinv[r] * factinv[n-r]) % MOD N, M = map(int, input().split()) for i in range(2, 2*N + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) ans = (comb(2*N, N) * 2*N) % MOD for _ in range(M): t, x, y = map(int, input().split()) if t == 1: x1, y1 = x+1, y else: x1, y1 = x, y+1 v = comb(x+y, x) * comb((N-x1)+(N-y1), N-x1) ans = (ans - v) % MOD print(ans)