#include <bits/stdc++.h>
using namespace std;
const long long int INF = 9223372036854775807;
const int MAXN = 100 + 24;
const int MAXX = 16 + 24;
const int mod = 1e9 + 7;
struct Node {
  long long int l, r, y;
} P[MAXN];
struct Matrix {
  int row, col;
  long long int m[MAXX][MAXX];
  void init(int row, int col) {
    this->row = row;
    this->col = col;
    for (int i = 0; i < row; ++i)
      for (int j = 0; j < col; ++j) m[i][j] = 0;
  }
} C, I;
Matrix operator*(const Matrix& a, const Matrix& b) {
  Matrix res;
  res.init(a.row, b.col);
  for (int k = 0; k < a.col; ++k) {
    for (int i = 0; i < res.row; ++i) {
      if (a.m[i][k] == 0) continue;
      for (int j = 0; j < res.col; ++j) {
        if (b.m[k][j] == 0) continue;
        res.m[i][j] = (a.m[i][k] * b.m[k][j] + res.m[i][j]) % mod;
      }
    }
  }
  return res;
}
Matrix operator+(const Matrix& a, const Matrix& b) {
  Matrix res;
  res.init(a.row, b.col);
  for (int i = 0; i < a.col; ++i) {
    for (int j = 0; j < res.row; ++j) {
      res.m[i][j] = (a.m[i][j] + b.m[i][j]) % mod;
    }
  }
  return res;
}
Matrix Mpow(Matrix A, long long int n) {
  Matrix ans = A, p = A;
  while (n) {
    if (n & 1) {
      ans = ans * p;
      n--;
    }
    n >>= 1;
    p = p * p;
  }
  return ans;
}
int main() {
  int n;
  long long int k;
  while (~scanf("%d%lld", &n, &k)) {
    for (int i = 0; i < n; i++) {
      scanf("%lld%lld%lld", &P[i].l, &P[i].r, &P[i].y);
    }
    C.init(16, 1);
    C.m[0][0] = 1;
    for (int i = 0; i < n; i++) {
      if (P[i].l >= k) {
        break;
      }
      Matrix res;
      res.init(16, 16);
      for (int j = 0; j < 16; j++) {
        if (j > P[i].y) {
          break;
        }
        for (int q = -1; q <= 1; q++) {
          if (j + q >= 0 && j + q <= P[i].y) {
            res.m[j][j + q] = 1;
          }
        }
      }
      res = Mpow(res, min(k, P[i].r) - min(k, P[i].l) - 1);
      for (int j = P[i].y + 1; j < 16; j++) {
        C.m[j][0] = 0;
      }
      C = C * res;
    }
    printf("%lld\n", C.m[0][0]);
  }
  return 0;
}
