#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
struct Matrix {
  int r, c;
  long long m[100 + 5][100 + 5];
  Matrix() {}
  Matrix(int R, int C) { r = R, c = C, memset(m, 0, sizeof(m)); }
  Matrix operator*(Matrix a) {
    Matrix b(r, a.c);
    for (int i = 1; i <= r; i++)
      for (int j = 1; j <= a.c; j++)
        for (int k = 1; k <= c; k++)
          b.m[i][j] =
              (b.m[i][j] + m[i][k] * a.m[k][j] % int(1e9 + 7)) % int(1e9 + 7);
    return b;
  }
  void print() {
    for (int i = 1; i <= r; i++)
      for (int j = 1; j <= c; j++)
        printf("%lld", m[i][j]), putchar(j == c ? '\n' : ' ');
    return;
  }
};
Matrix Pow(Matrix x, long long y) {
  Matrix ret(x.r, x.c);
  for (int i = 1; i <= x.r; i++) ret.m[i][i] = 1;
  while (y) {
    if (y & 1) ret = ret * x;
    x = x * x;
    y >>= 1;
  }
  return ret;
}
long long f[20];
Matrix A, B, C;
void Init() {
  f[1] = 1;
  A = Matrix();
  B = Matrix();
  for (int i = 1; i <= 16; i++) A.m[i - 1][i] = A.m[i][i] = A.m[i + 1][i] = 1;
  return;
}
int main() {
  Init();
  int n = read();
  long long k = read(), tmp = 16;
  for (int i = 1; i <= n; i++) {
    long long a = read(), b = read(), c = read() + 1;
    if (a >= k) continue;
    if (b > k) b = k;
    A.r = A.c = c;
    C = Pow(A, b - a);
    B.r = 1, B.c = c;
    for (int i = 1; i <= min(tmp, c); i++) B.m[1][i] = f[i];
    for (int i = min(tmp, c) + 1; i <= 16; i++) B.m[1][i] = f[i] = 0;
    B = B * C;
    for (int i = 1; i <= c; i++) f[i] = B.m[1][i];
    tmp = c;
  }
  printf("%lld\n", f[1]);
  return 0;
}
