class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, M = map(int, input().split()) mod = 10**9+7 H = [0] * (N+1) r2l = [0] * (N+1) c = 0 for _ in range(M): l, r, p = map(int, input().split()) if p: H[l-1] += 1 H[r] -= 1 c += 1 else: r2l[r] = l bt = Bit(N+1) bt.add(1, pow(2, N, mod)) #bt[2..N+1]を1..Nに割り当て #bt[i] = (A[i-1] が最後の0となるようなr