#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
const long long inf = 1e18;
const double eps = 1e-6;
typedef struct Matrix {
  long long mat[17][17];
} matrix;
matrix A, B, pre;
matrix matrix_mul(matrix a, matrix b, long long len) {
  matrix c;
  memset(c.mat, 0, sizeof(c.mat));
  for (long long i = 0; i <= len; i++)
    for (long long j = 0; j <= len; j++)
      for (long long k = 0; k <= len; k++) {
        c.mat[i][j] += ((a.mat[i][k]) % mod * (b.mat[k][j]) % mod) % mod;
        c.mat[i][j] %= mod;
      }
  return c;
}
matrix matrix_quick_power(matrix a, long long k, long long len) {
  matrix b;
  memset(b.mat, 0, sizeof(b.mat));
  for (long long i = 0; i <= len; i++) b.mat[i][i] = 1;
  while (k) {
    if (k % 2 == 1) b = matrix_mul(a, b, len);
    k /= 2;
    a = matrix_mul(a, a, len);
  }
  return b;
}
int main() {
  long long n, e;
  while (~scanf("%I64d%I64d", &n, &e)) {
    memset(pre.mat, 0, sizeof(pre.mat));
    memset(A.mat, 0, sizeof(A.mat));
    for (long long i = 0; i < 16; i++)
      for (long long j = i - 1; j < i + 2 && j < 16; j++)
        if (j >= 0 && j <= 15) A.mat[i][j] = 1;
    long long flag = 0;
    pre.mat[0][0] = 1;
    for (long long i = 1; i <= n; i++) {
      long long L, R, y;
      scanf("%I64d%I64d%I64d", &L, &R, &y);
      if (R > e) R = e, flag = 1;
      B = matrix_quick_power(A, R - L, y);
      for (long long j = y + 1; j <= 15; j++) pre.mat[j][0] = 0;
      B = matrix_mul(B, pre, y);
      for (long long j = 0; j <= y; j++) pre.mat[j][0] = B.mat[j][0];
      if (flag == 1) break;
    }
    printf("%I64d\n", pre.mat[0][0]);
  }
  return 0;
}
