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>
typedef long long TMat[3][3];
const long long md = 1e9 + 7;
using namespace std;
int n;
long long m;
int tmp[3];
TMat base1, base2, f, f_;
vector<pair<long long, pair<long long, long long> > > v;
void One(TMat &a, int n) {
  memset(a, 0, sizeof a);
  for (int i = 0; i < n; i++) a[i][i] = 1;
}
void Copy(TMat a, int m, int n, TMat &b) {
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) b[i][j] = a[i][j];
}
void Mul(TMat &a, TMat &b, int m, int n, int p, TMat &c) {
  memset(c, 0, sizeof c);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < p; k++) c[i][k] = (c[i][k] + a[i][j] * b[j][k]) % md;
}
void Pow(TMat &a, int n, long long x, TMat &b) {
  TMat e, tmp;
  One(b, 3);
  Copy(a, 3, 3, e);
  while (x) {
    if (x & 1) {
      Mul(e, b, 3, 3, 3, tmp);
      Copy(tmp, 3, 3, b);
    }
    x >>= 1;
    Mul(e, e, 3, 3, 3, tmp);
    Copy(tmp, 3, 3, e);
  }
}
int main() {
  TMat BASE_MAT = {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}};
  scanf("%d%lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    long long x, y, z;
    scanf("%lld%lld%lld", &x, &y, &z);
    v.push_back(make_pair(y, make_pair(x - 1, 1)));
    v.push_back(make_pair(z + 1, make_pair(x - 1, -1)));
  }
  sort(v.begin(), v.end());
  long long cur = 1;
  memset(f, 0, sizeof f);
  f[1][0] = 1;
  Copy(BASE_MAT, 3, 3, base1);
  for (int i = 0; i < v.size(); i++) {
    tmp[v[i].second.first] += v[i].second.second;
    if (i == v.size() - 1 || v[i + 1].first != v[i].first) {
      Pow(base1, 3, v[i].first - cur - 1, base2);
      Mul(base2, f, 3, 3, 1, f_);
      Copy(f_, 3, 1, f);
      Copy(BASE_MAT, 3, 3, base1);
      for (int j = 0; j <= 2; j++)
        if (tmp[j] != 0) {
          memset(base1[j], 0, sizeof base1[j]);
        }
      Mul(base1, f, 3, 3, 1, f_);
      Copy(f_, 3, 1, f);
      cur = v[i].first;
    }
  }
  if (cur != m) {
    Pow(BASE_MAT, 3, m - cur, base2);
    Mul(base2, f, 3, 3, 1, f_);
    Copy(f_, 3, 1, f);
  }
  printf("%lld", f[1][0]);
}
