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 long long N = 2e5 + 10;
const long long mod = 1e9 + 7;
map<long long, vector<pair<long long, long long>>> mp;
long long arr[3];
vector<vector<long long>> multiply(vector<vector<long long>> a,
                                   vector<vector<long long>> b) {
  vector<vector<long long>> mul(3);
  for (long long i = 0; i < 3; i++) {
    mul[i].assign(3, 0);
    for (long long j = 0; j < 3; j++) {
      mul[i][j] = 0;
      for (long long k = 0; k < 3; k++)
        mul[i][j] += ((a[i][k] % mod) * (b[k][j] % mod)) % mod;
      mul[i][j] %= mod;
    }
  }
  return mul;
}
vector<vector<long long>> MatrixPow(vector<vector<long long>> F, long long p) {
  if (p == 1) return F;
  vector<vector<long long>> res = MatrixPow(F, p / 2);
  res = multiply(res, res);
  if (p % 2) {
    res = multiply(res, F);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    long long x, y, z;
    cin >> x >> y >> z;
    mp[y - 1].push_back({x, 1});
    mp[z].push_back({x, 0});
  }
  vector<vector<long long>> res = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
  long long crPos = 1;
  for (auto i : mp) {
    long long dis = i.first - crPos;
    vector<vector<long long>> init = {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}};
    for (long long x = 0; x < 3; ++x) {
      for (long long y = 0; y < 3; ++y) {
        if (arr[y] > 0) init[x][y] = 0;
      }
    }
    if (dis) {
      res = multiply(res, MatrixPow(init, dis));
      crPos = i.first;
    }
    for (auto j : i.second) {
      if (j.second) ++arr[j.first - 1];
    }
    for (auto j : i.second) {
      if (!j.second) --arr[j.first - 1];
    }
  }
  if (crPos < m) {
    vector<vector<long long>> init = {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}};
    res = multiply(res, MatrixPow(init, m - crPos));
  }
  cout << res[1][1] << endl;
}
