#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > A;
vector<vector<long long> > curr;
int n, c;
long long k, u, v, base = 1000000007;
void pr(vector<vector<long long> > A) {
  int m = A.size(), n = A[0].size();
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) cout << A[i][j] << " ";
    cout << endl;
  }
  cout << "-----------------\n";
}
vector<vector<long long> > mul(vector<vector<long long> > A,
                               vector<vector<long long> > B) {
  int m = A.size(), n = A[0].size(), k = B[0].size();
  vector<vector<long long> > R;
  for (int i = 0; i < m; i++) {
    vector<long long> newRow;
    R.push_back(newRow);
    for (int j = 0; j < k; j++) {
      R[i].push_back(0ll);
      for (int t = 0; t < n; t++)
        R[i][j] = (R[i][j] + A[i][t] * B[t][j]) % base;
    }
  }
  return R;
}
vector<vector<long long> > pw(vector<vector<long long> > A, long long n) {
  if (n == 1) return A;
  vector<vector<long long> > T = pw(A, n / 2);
  if (n % 2 == 0)
    return mul(T, T);
  else
    return mul(mul(T, T), A);
}
int main() {
  cin >> n >> k;
  vector<long long> tmp;
  tmp.push_back(0);
  curr.push_back(tmp);
  curr[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> u >> v >> c;
    v = min(v, k);
    while (curr.size() <= c) curr.push_back(tmp);
    while (curr.size() > c + 1) curr.pop_back();
    if (v - u == 0) continue;
    A.resize(0);
    for (int i = 0; i <= c; i++) {
      vector<long long> newRow;
      A.push_back(newRow);
      for (int j = 0; j <= c; j++)
        if (abs(i - j) <= 1)
          A[i].push_back(1ll);
        else
          A[i].push_back(0ll);
    }
    curr = mul(pw(A, v - u), curr);
  }
  cout << curr[0][0];
}
