#include <bits/stdc++.h>
using namespace std;
struct Matrix {
  long long n, m, f[16][16];
  void print() {
    for (long long i = 0; i <= n; i++)
      for (long long j = 0; j <= m; j++)
        printf("%I64d%c", f[i][j], j < m ? ' ' : '\n');
    cout << endl;
  }
  void init(long long nn, long long mm) {
    n = nn, m = mm;
    for (long long i = 0; i <= n; i++)
      for (long long j = 0; j <= m; j++) f[i][j] = 0;
  }
  void set_E(long long nn) {
    n = m = nn;
    for (long long i = 0; i <= n; i++) f[i][i] = 1;
  }
  Matrix operator*(const Matrix &t) const {
    Matrix res;
    res.init(n, t.m);
    for (long long i = 0; i <= n; i++)
      for (long long j = 0; j <= t.m; j++)
        for (long long k = 0; k <= m; k++)
          (res.f[i][j] += f[i][k] * t.f[k][j] % 1000000007) %= 1000000007;
    return res;
  }
  Matrix operator^(long long k) const {
    Matrix base = *this, res;
    res.init(n, n);
    res.set_E(n);
    while (k > 0) {
      if (k & 1) res = res * base;
      base = base * base;
      k >>= 1;
    }
    return res;
  }
} p, q;
long long n, k, a[101], b[101], c[101];
int main() {
  scanf("%I64d%I64d", &n, &k);
  for (long long i = 1; i <= n; i++)
    scanf("%I64d%I64d%I64d", &a[i], &b[i], &c[i]);
  b[n] = k;
  p.init(1, 15);
  q.init(15, 15);
  p.f[1][0] = 1;
  for (long long i = 1; i <= n; i++) {
    if (b[i] == a[i]) continue;
    for (long long j = 0; j <= 15; j++) {
      long long x = j <= c[i] ? 1 : 0;
      q.f[j][j] = x;
      if (j > 0) q.f[j - 1][j] = x;
      if (j < 15) q.f[j + 1][j] = x;
    }
    p = p * (q ^ (b[i] - a[i] - 1));
    if (i < n && c[i + 1] < c[i])
      for (long long j = c[i + 1] + 1; j <= c[i]; j++) {
        q.f[j][j] = 0;
        if (j > 0) q.f[j - 1][j] = 0;
        if (j < 15) q.f[j + 1][j] = 0;
      }
    p = p * q;
  }
  printf("%I64d\n", p.f[1][0]);
  return 0;
}
