#include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
const long long INF = 0x7f7f7f7f;
void add(long long &x, long long y) {
  x += y;
  if (x >= mo) x -= mo;
}
struct matrix {
  long long c[20][20], n, m;
  matrix() {
    memset(c, 0, sizeof(c));
    n = m = 0;
  }
  matrix operator*(const matrix &rhs) const {
    matrix res;
    res.n = n;
    res.m = rhs.m;
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= m; k++)
        for (int j = 1; j <= rhs.m; j++)
          add(res.c[i][j], c[i][k] * rhs.c[k][j] % mo);
    return res;
  }
  void print() {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) printf("%lld ", c[i][j]);
      puts("");
    }
  }
} A, B;
matrix qkpow(matrix a, long long t) {
  matrix res;
  res.n = res.m = a.n;
  for (int i = 1; i <= res.n; i++) res.c[i][i] = 1;
  while (t) {
    if (t & 1LL) res = res * a;
    a = a * a;
    t >>= 1;
  }
  return res;
}
long long n, k;
signed main() {
  scanf("%lld %lld", &n, &k);
  B.n = 1;
  B.m = 16;
  B.c[1][1] = 1;
  for (int p = 1; p <= n; p++) {
    long long l, r, h;
    scanf("%lld %lld %lld", &l, &r, &h);
    r = min(r, k);
    A.n = A.m = 16;
    h++;
    for (int i = 1; i <= 16; i++)
      for (int j = 1; j <= 16; j++) A.c[i][j] = 0;
    for (int i = 1; i <= 16; i++) {
      if (i > 1) A.c[i - 1][i] = 1;
      A.c[i][i] = 1;
      if (i < 16) A.c[i + 1][i] = 1;
    }
    for (int i = 1; i <= 16; i++)
      for (int j = h + 1; j <= 16; j++) A.c[i][j] = 0;
    if (h < 16) A.c[h + 1][h] = 0;
    B = B * qkpow(A, r - l);
  }
  printf("%lld\n", B.c[1][1]);
  return 0;
}
