#include <bits/stdc++.h>
using namespace std;
long long int mat[16][16];
long long int prv[16], now[16];
inline void mul(long long int a[][16], long long int b[][16],
                long long int c[][16]) {
  long long int str[16][16] = {{0}};
  for (long long int i = 0; i < 16; i++)
    for (long long int j = 0; j < 16; j++)
      for (long long int k = 0; k < 16; k++)
        str[i][j] = (str[i][j] + (a[i][k] * b[k][j]) % 1000000007) % 1000000007;
  for (long long int i = 0; i < 16; i++)
    for (long long int j = 0; j < 16; j++) c[i][j] = str[i][j];
}
inline void pow(long long int x[][16], long long int y) {
  long long int ans[16][16] = {{0}};
  for (long long int i = 0; i < 16; i++) ans[i][i] = 1;
  while (y > 0) {
    if (y & 1) mul(x, ans, ans);
    y = y >> 1;
    mul(x, x, x);
  }
  for (long long int i = 0; i < 16; i++)
    for (long long int j = 0; j < 16; j++)
      now[i] = (now[i] + ans[i][j] * prv[j]) % 1000000007;
  for (long long int i = 0; i < 16; i++) prv[i] = now[i];
}
int main() {
  int begtime = clock();
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  for (long long int i = 1; i < 15; i++)
    mat[i][i - 1] = mat[i][i] = mat[i][i + 1] = 1;
  mat[0][0] = mat[0][1] = mat[15][14] = mat[15][15] = prv[0] = 1;
  long long int n, k;
  cin >> n >> k;
  pair<pair<long long int, long long int>, long long int> ranges[n];
  for (long long int i = 0; i < n; i++)
    cin >> ranges[i].first.first >> ranges[i].first.second >> ranges[i].second;
  ranges[n - 1].first.second = k;
  for (long long int i = 0; i < n; i++) {
    long long int m[16][16];
    for (long long int j = 0; j < 16; j++)
      for (long long int k = 0; k < 16; k++)
        if (k <= ranges[i].second)
          m[j][k] = mat[j][k];
        else
          m[j][k] = 0;
    for (long long int j = ranges[i].second + 1; j <= 15; j++) prv[j] = 0;
    for (long long int i = 0; i < 16; i++) now[i] = 0;
    pow(m, ranges[i].first.second - ranges[i].first.first);
    for (long long int j = ranges[i].second + 1; j <= 15; j++) prv[j] = 0;
  }
  cout << prv[0];
  int endtime = clock();
  cerr << "\n\n"
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC
       << " ms\n\n";
  return 0;
}
