#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e18;
const long long LOG = 61;
const long long MOD = 1e9 + 7;
long long n, m;
vector<vector<long long>> mult(vector<vector<long long>> &a,
                               vector<vector<long long>> &b) {
  vector<vector<long long>> ans(3, vector<long long>(3, 0));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % MOD;
      }
    }
  }
  return ans;
}
vector<long long> mult(vector<vector<long long>> &a, vector<long long> &b) {
  vector<long long> ans(3, 0);
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      ans[i] = (ans[i] + a[i][j] * b[j]) % MOD;
    }
  }
  return ans;
}
vector<vector<long long>> preM[LOG];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  vector<vector<long long>> M{{1, 1, 0}, {1, 1, 1}, {0, 1, 1}};
  vector<vector<long long>> ev;
  for (int i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ev.push_back({b - 1, 1, a - 1});
    ev.push_back({c, -1, a - 1});
  }
  ev.push_back({m, 0, 1});
  sort(ev.begin(), ev.end());
  vector<long long> bl{0, 0, 0};
  vector<long long> st{0, 1, 0};
  vector<vector<long long>> curM = M;
  long long pos = 1;
  for (auto e : ev) {
    long long np = e[0], a = e[2], d = e[1];
    if (np > pos) {
      long long diff = np - pos;
      long long p = 1LL;
      while (diff) {
        if (diff & p) {
          diff -= p;
          st = mult(curM, st);
        }
        p <<= 1LL;
        curM = mult(curM, curM);
      }
      pos = np;
    }
    bl[a] += d;
    curM = M;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (bl[i]) curM[i][j] = 0;
      }
    }
  }
  cout << st[1] << endl;
}
