#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > v(16, vector<long long>(16));
vector<vector<long long> > an = v;
vector<long long> ans(16, 0);
struct mt {
  long long a, b, c;
};
void upd(long long c) {
  long long i, j;
  for (i = 0; i < 16; i++)
    for (j = 0; j < 16; j++) v[i][j] = (abs(j - i) <= 1 && i <= c && j <= c);
  for (i = 0; i < 16; i++)
    for (j = 0; j < 16; j++) an[i][j] = (i == j);
}
void sq(vector<vector<long long> >& ani, vector<vector<long long> >& okay) {
  long long i, j, k;
  vector<vector<long long> > res(16, vector<long long>(16, 0));
  for (i = 0; i < 16; i++)
    for (j = 0; j < 16; j++)
      for (k = 0; k < 16; k++) {
        res[i][j] += ani[k][j] * okay[i][k];
        res[i][j] %= 1000000007;
      }
  ani = res;
}
void exp(long long p) {
  while (p) {
    if (p & 1) sq(an, v);
    sq(v, v);
    p /= 2;
  }
}
void exp2() {
  vector<long long> res(16, 0);
  long long i, j;
  for (i = 0; i < 16; i++)
    for (j = 0; j < 16; j++) {
      res[i] += an[i][j] * ans[j];
      res[i] %= 1000000007;
    }
  ans = res;
}
int main() {
  ans[0] = 1;
  long long n, k;
  cin >> n >> k;
  long long i, j;
  mt arr[n + 1];
  for (i = 0; i < n; i++) {
    cin >> arr[i].a >> arr[i].b >> arr[i].c;
  }
  for (i = 0; i < n; i++) {
    if (i == n - 1) arr[i].b = k;
    for (j = arr[i].c + 1; j < 16; j++) ans[j] = 0;
    upd(arr[i].c);
    exp(arr[i].b - arr[i].a);
    exp2();
  }
  ans[0] += 1000000007;
  ans[0] %= 1000000007;
  cout << ans[0];
  return 0;
}
