import sys from typing import List, Tuple def int1(x: str, /): return int(x) - 1 def input(): return sys.stdin.readline().rstrip('\n') def dbg(*args, **kwargs): print(*(repr(arg) for arg in args), *(f'{k}: {repr(v)}' for k, v in kwargs.items()), sep='; ', file=sys.stderr) M = 10 ** 9 + 7 def fact(x, memo=[1]): if len(memo) <= x: for i in range(len(memo), x + 1): memo.append(i * memo[i - 1] % M) return memo[x] def main(): n, m = map(int, input().split()) tot = 2 * n * fact(2 * n) * pow(fact(n), -2, M) % M for _ in range(m): t, x, y = map(int, input().split()) tot -= fact(x + y) * pow(fact(x) * fact(y), -1, M) * fact((2 * n - 1) - (x + y)) * \ pow(fact(n - (x + (0 if t == 2 else 1))) * fact(n - (y + (0 if t == 1 else 1))), -1, M) tot %= M return tot def _start(): ret = main() if ret is not None: if isinstance(ret, List) or isinstance(ret, Tuple): print(*ret) else: print(ret) if __name__ == '__main__': _start()