#include <bits/stdc++.h>
const int LIM = 16;
const int MOD = 1e9 + 7;
struct matrix {
  long long val[LIM][LIM];
};
long long pos, tar;
std::queue<std::pair<long long, int> > q;
matrix ans, tmp;
matrix operator*(const matrix &lhs, const matrix &rhs) {
  matrix res;
  memset(res.val, 0x00, sizeof(res.val));
  for (int i = 0; i < LIM; ++i)
    for (int j = 0; j < LIM; ++j)
      for (int k = 0; k < LIM; ++k)
        (res.val[i][j] += lhs.val[i][k] * rhs.val[k][j]) %= MOD;
  return res;
}
matrix operator^(matrix base, long long exp) {
  matrix res;
  for (int i = 0; i < LIM; ++i)
    for (int j = 0; j < LIM; ++j) res.val[i][j] = i == j;
  while (exp > 0) {
    if (exp & 1) res = res * base;
    base = base * base;
    exp >>= 1;
  }
  return res;
}
int main() {
  int n;
  scanf("%d%lld", &n, &tar);
  while (n--) {
    long long a, b;
    int c;
    scanf("%lld%lld%d", &a, &b, &c);
    q.push({std::min(tar, b), c});
  }
  ans.val[0][0] = 1;
  while (pos != tar) {
    long long step = q.front().first - pos;
    memset(tmp.val, 0x00, sizeof(tmp.val));
    for (int i = 0; i <= q.front().second; ++i)
      for (int j = std::max(0, i - 1); j <= std::min(q.front().second, i + 1);
           ++j)
        tmp.val[i][j] = 1;
    tmp = tmp ^ step;
    ans = ans * tmp;
    pos += step;
    q.pop();
  }
  printf("%lld\n", ans.val[0][0]);
}
