#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct matrix {
  vector<vector<long long int>> s =
      vector<vector<long long int>>(20, vector<long long int>(20, 0));
};
matrix A, B, mid;
matrix qmul(matrix &a, matrix &b, int len) {
  matrix ans;
  for (int i = 0; i <= len; ++i)
    for (int k = 0; k <= len; ++k)
      for (int j = 0; j <= len; ++j) {
        ans.s[i][j] = (ans.s[i][j] + a.s[i][k] * b.s[k][j] % mod) % mod;
      }
  return ans;
}
matrix qmod(matrix a, long long k, int len) {
  matrix E;
  for (int i = 0; i <= len; ++i) E.s[i][i] = 1;
  while (k) {
    if (k & 1) E = qmul(E, a, len);
    a = qmul(a, a, len);
    k >>= 1;
  }
  return E;
}
int main() {
  long long n;
  long long k;
  cin >> n >> k;
  for (int i = 0; i <= 15; ++i) {
    for (int j = i - 1; j <= i + 1 && j <= 15; ++j) {
      if (j >= 0 && j <= 15) A.s[i][j] = 1;
    }
  }
  mid.s[0][0] = 1;
  bool flag = 0;
  for (int i = 1; i <= n; i++) {
    long long l, r;
    int y;
    cin >> l >> r >> y;
    if (r > k) r = k, flag = 1;
    B = qmod(A, r - l, y);
    for (int j = y + 1; j <= 15; ++j) {
      mid.s[j][0] = 0;
    }
    B = qmul(B, mid, y);
    for (int j = 0; j <= 15; ++j) {
      mid.s[j][0] = B.s[j][0];
    }
    if (flag) break;
  }
  cout << B.s[0][0];
  return 0;
}
