You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.

You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:

  * (i - 1, j + 1) — only if i > 1, 
  * (i, j + 1), or 
  * (i + 1, j + 1) — only if i < 3. 



However, there are n obstacles blocking your path. k-th obstacle is denoted by three integers ak, lk and rk, and it forbids entering any cell (ak, j) such that lk ≤ j ≤ rk.

You have to calculate the number of different paths from (2, 1) to (2, m), and print it modulo 109 + 7.

Input

The first line contains two integers n and m (1 ≤ n ≤ 104, 3 ≤ m ≤ 1018) — the number of obstacles and the number of columns in the matrix, respectively.

Then n lines follow, each containing three integers ak, lk and rk (1 ≤ ak ≤ 3, 2 ≤ lk ≤ rk ≤ m - 1) denoting an obstacle blocking every cell (ak, j) such that lk ≤ j ≤ rk. Some cells may be blocked by multiple obstacles.

Output

Print the number of different paths from (2, 1) to (2, m), taken modulo 109 + 7. If it is impossible to get from (2, 1) to (2, m), then the number of paths is 0.

Example

Input

2 5
1 3 4
2 2 3


Output

2
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void addRange(set<pair<long long, long long>> &ranges, long long l,
              long long r) {
  auto it = ranges.lower_bound({l, -1});
  while (it != ranges.end() && it->second <= r) it = ranges.erase(it);
  if (it != ranges.end() && it->first <= r) {
    ranges.emplace(r + 1, it->second);
    it = ranges.erase(it);
  }
  if (it != ranges.begin()) {
    --it;
    if (it->second >= l) {
      ranges.emplace(it->first, l - 1);
      if (it->second > r) ranges.emplace(r + 1, it->second);
      ranges.erase(it);
    }
  }
  ranges.emplace(l, r);
}
vector<vector<long long>> matrixMult(const vector<vector<long long>> A,
                                     const vector<vector<long long>> B) {
  vector<vector<long long>> C(A.size(), vector<long long>(B[0].size(), 0));
  for (int i = 0; i < C.size(); ++i)
    for (int j = 0; j < C[0].size(); ++j)
      for (int k = 0; k < A[0].size(); ++k)
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
  return C;
}
vector<vector<long long>> matrixIdentity(const int n) {
  vector<vector<long long>> M(n, vector<long long>(n, 0));
  for (int i = 0; i < n; ++i) M[i][i] = 1;
  return M;
}
vector<vector<long long>> matrixPow(vector<vector<long long>> A, long long k) {
  auto B = matrixIdentity(A.size());
  for (; k; k >>= 1) {
    if (k & 1) B = matrixMult(A, B);
    A = matrixMult(A, A);
  }
  return B;
}
long long n, m;
set<pair<long long, long long>> obstacles[3];
int get(long long a, long long i) {
  auto it = obstacles[a].upper_bound({i, 2e18});
  if (it == obstacles[a].begin()) return 0;
  --it;
  return it->second >= i;
}
int get(long long i) { return get(2, i) << 2 | get(1, i) << 1 | get(0, i); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  set<long long> events = {m - 1};
  for (int i = 0; i < n; ++i) {
    long long a, l, r;
    cin >> a >> l >> r;
    addRange(obstacles[--a], --l, --r);
    events.insert(l - 1);
    events.insert(r);
  }
  const vector<vector<vector<long long>>> Matrixes = {
      {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}}, {{0, 1, 0}, {0, 1, 1}, {0, 1, 1}},
      {{1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{0, 0, 0}, {0, 0, 1}, {0, 0, 1}},
      {{1, 1, 0}, {1, 1, 0}, {0, 1, 0}}, {{0, 1, 0}, {0, 1, 0}, {0, 1, 0}},
      {{1, 0, 0}, {1, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}};
  long long pos = 0;
  vector<long long> dp = {0, 1, 0};
  while (events.size()) {
    const auto &M = Matrixes[get(pos + 1)];
    const long long k = *events.begin() - pos;
    events.erase(events.begin());
    dp = matrixMult(vector<vector<long long>>{dp}, matrixPow(M, k))[0];
    pos += k;
  }
  cout << dp[1];
  return 0;
}
