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;
vector<long long int> ans;
vector<vector<long long int>> mat;
void matrix_multiply(std::vector<vector<long long int>> &a,
                     vector<vector<long long int>> b) {
  vector<vector<long long int>> demo;
  demo = a;
  for (long long int i = 0; i < 3; i++) {
    for (long long int j = 0; j < 3; j++) {
      a[i][j] = 0;
      for (long long int k = 0; k < 3; k++) {
        a[i][j] +=
            ((demo[i][k] % 1000000007) * (b[k][j] % 1000000007)) % 1000000007;
        a[i][j] = a[i][j] % 1000000007;
      }
    }
  }
}
void matirx_multiply_f(std::vector<long long int> &a,
                       vector<vector<long long int>> b) {
  vector<long long int> demo;
  demo = a;
  for (long long int i = 0; i < 3; i++) {
    a[i] = 0;
    for (long long int j = 0; j < 3; j++) {
      a[i] += ((demo[j] % 1000000007) * (b[i][j] % 1000000007)) % 1000000007;
      a[i] = a[i] % 1000000007;
    }
  }
}
void multiply(long long int pow) {
  vector<vector<long long int>> a;
  a = mat;
  vector<vector<long long int>> b;
  b.assign(3, vector<long long int>(3, 0));
  b[0][0] = 1, b[1][1] = 1, b[2][2] = 1;
  while (pow > 0) {
    if (pow & 1) {
      matrix_multiply(b, a);
    }
    matrix_multiply(a, a);
    pow >>= 1;
  }
  matirx_multiply_f(ans, b);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int n, m;
  cin >> n >> m;
  long long int x = n;
  vector<pair<long long int, pair<long long int, long long int>>> b;
  while (x--) {
    long long int a, l, r;
    cin >> a >> l >> r;
    b.push_back({l - 1, {1, a}});
    b.push_back({r, {2, a}});
  }
  ans.assign(3, 0);
  ans[1] = 1;
  mat.assign(3, vector<long long int>(3, 0));
  mat[0] = {1, 1, 0};
  mat[1] = {1, 1, 1};
  mat[2] = {0, 1, 1};
  sort(b.begin(), b.end());
  long long int id = -1;
  multiply(b[id + 1].first - 1);
  long long int o1 = 0, o2 = 0, o3 = 0;
  for (long long int i = b[0].first; i < m; i++) {
    while (id < 2 * n - 1 && b[id + 1].first == i) {
      id++;
      if (b[id].second.second == 1) {
        if (b[id].second.first == 1)
          o1++;
        else
          o1--;
        if (o1 > 0)
          mat[0] = {0, 0, 0};
        else
          mat[0] = {1, 1, 0};
      } else if (b[id].second.second == 2) {
        if (b[id].second.first == 1)
          o2++;
        else
          o2--;
        if (o2 > 0)
          mat[1] = {0, 0, 0};
        else
          mat[1] = {1, 1, 1};
      } else {
        if (b[id].second.first == 1)
          o3++;
        else
          o3--;
        if (o3 > 0)
          mat[2] = {0, 0, 0};
        else
          mat[2] = {0, 1, 1};
      }
    }
    if (id + 1 < 2 * n)
      multiply(b[id + 1].first - b[id].first), i = b[id + 1].first - 1;
    else
      multiply(m - b[id].first), i = m - 1;
  }
  cout << ans[1];
  return 0;
}
