#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const long long mod = 1e9 + 7;
long long l[N], r[N], h[N], base[20][20], vec[20], A[20][20], B[20][20],
    T[20][20], t[20];
void qmod(long long h, long long exp) {
  memcpy(B, base, sizeof(base));
  while (!(exp & 1)) {
    exp >>= 1;
    memset(T, 0, sizeof(T));
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= h; j++)
        for (int k = 1; k <= h; k++)
          T[i][j] = (T[i][j] + B[i][k] * B[k][j]) % mod;
    memcpy(B, T, sizeof(T));
  }
  memcpy(A, B, sizeof(B));
  exp >>= 1;
  while (exp) {
    memset(T, 0, sizeof(T));
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= h; j++)
        for (int k = 1; k <= h; k++)
          T[i][j] = (T[i][j] + B[i][k] * B[k][j]) % mod;
    memcpy(B, T, sizeof(T));
    if (exp & 1) {
      memset(T, 0, sizeof(T));
      for (int i = 1; i <= h; i++)
        for (int j = 1; j <= h; j++)
          for (int k = 1; k <= h; k++)
            T[i][j] = (T[i][j] + A[i][k] * B[k][j]) % mod;
      memcpy(A, T, sizeof(T));
    }
    exp >>= 1;
  }
}
int main() {
  int n;
  long long k;
  scanf("%d%I64d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%I64d%I64d%I64d", &l[i], &r[i], &h[i]);
  for (int i = 1; i <= 16; i++)
    for (int j = i - 1; j <= i + 1; j++) base[i][j] = 1;
  r[n] = k;
  vec[1] = 1;
  for (int w = 1; w <= n; w++) {
    if (r[w] == l[w]) continue;
    h[w]++;
    qmod(h[w], r[w] - l[w]);
    memset(t, 0, sizeof(t));
    for (int i = 1; i <= h[w]; i++)
      for (int j = 1; j <= h[w]; j++) t[i] = (t[i] + vec[j] * A[i][j]) % mod;
    memcpy(vec, t, sizeof(t));
  }
  printf("%I64d\n", vec[1]);
  return 0;
}
