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;
const int maxn = 5e4 + 7;
vector<vector<long long> > C(3, vector<long long>(3)),
    temp(3, vector<long long>(3)), bst(1, vector<long long>(3));
struct block {
  int a;
  long long l, r;
} blk[maxn];
long long imos[5][maxn], disc[maxn], mos[5], map[maxn];
void init() {
  C[0][0] = 1;
  C[1][0] = 1;
  C[2][0] = 0;
  C[0][1] = 1;
  C[1][1] = 1;
  C[2][1] = 1;
  C[0][2] = 0;
  C[1][2] = 1;
  C[2][2] = 1;
  bst[0][0] = 0;
  bst[0][1] = 1;
  bst[0][2] = 0;
  temp = C;
}
vector<vector<long long> > operator*(const vector<vector<long long> >& A,
                                     const vector<vector<long long> >& B) {
  vector<vector<long long> > ans(A.size(), vector<long long>(B[0].size()));
  for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < B[0].size(); ++j)
      for (int k = 0; k < A[0].size(); ++k)
        ans[i][j] = (ans[i][j] + 1LL * A[i][k] * B[k][j]) % mod;
  return ans;
}
vector<vector<long long> > quick_mod(vector<vector<long long> > X,
                                     long long n) {
  vector<vector<long long> > ans(X.size(), vector<long long>(X.size()));
  for (int i = 0; i < X.size(); ++i) ans[i][i] = 1;
  while (n > 0) {
    if (n & 1) ans = ans * X;
    X = X * X;
    n >>= 1;
  }
  return (ans);
}
int main() {
  int n;
  long long ans, cnt = 0;
  long long m;
  init();
  scanf("%d%lld", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%lld%lld", &blk[i].a, &blk[i].l, &blk[i].r);
    disc[cnt++] = blk[i].l - 1;
    disc[cnt++] = blk[i].r;
  }
  disc[cnt++] = 1;
  disc[cnt++] = m;
  sort(disc, disc + cnt);
  cnt = unique(disc, disc + cnt) - disc;
  for (int i = 0; i < n; ++i) {
    int ls = lower_bound(disc, disc + cnt, blk[i].l) - disc;
    int rs = lower_bound(disc, disc + cnt, blk[i].r) - disc;
    ++imos[blk[i].a][ls];
    --imos[blk[i].a][rs + 1];
  }
  memset(mos, 0, sizeof(mos));
  for (int i = 1; i < cnt; ++i) {
    long long len = disc[i] - disc[i - 1];
    C = temp;
    for (int j = 1; j <= 3; ++j) {
      mos[j] += imos[j][i];
      if (mos[j]) C[0][j - 1] = C[1][j - 1] = C[2][j - 1] = 0;
    }
    bst = bst * quick_mod(C, len);
  }
  printf("%lld\n", bst[0][1]);
  return 0;
}
