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 N = 1e4 + 10;
const int mod = 1e9 + 7;
struct Matrix {
  long long A[4][4];
  Matrix() { memset(A, 0, sizeof(A)); }
  Matrix operator*(const Matrix& rhs) {
    Matrix res;
    for (long long i = 0; i < 3; i++)
      for (long long j = 0; j < 3; j++)
        for (long long k = 0; k < 3; k++)
          res.A[i][j] = (res.A[i][j] + 1ll * A[i][k] * rhs.A[k][j] % mod) % mod;
    return res;
  }
  void build() {
    memset(A, 0, sizeof(A));
    A[0][0] = A[0][1] = A[1][0] = A[1][1] = A[1][2] = A[2][1] = A[2][2] = 1;
  }
};
Matrix qkpow(Matrix B, long long idx) {
  Matrix E;
  for (long long i = 0; i <= 3; i++) E.A[i][i] = 1;
  while (idx) {
    if (idx & 1) E = E * B;
    idx >>= 1;
    B = B * B;
  }
  return E;
}
long long n, m, P[N * 2], l[N], r[N], t[N], len;
long long book[4][N * 2];
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> t[i] >> l[i] >> r[i];
    P[++len] = l[i] - 1;
    P[++len] = r[i];
  }
  P[++len] = 1;
  P[++len] = m;
  sort(P + 1, P + 1 + len);
  len = unique(P + 1, P + 1 + len) - P - 1;
  for (long long i = 1; i <= n; i++) {
    long long tl = lower_bound(P + 1, P + 1 + len, l[i]) - P,
              tr = lower_bound(P + 1, P + 1 + len, r[i]) - P;
    book[t[i] - 1][tl]++;
    book[t[i] - 1][tr + 1]--;
  }
  Matrix ans;
  ans.A[1][0] = 1;
  long long col[3] = {0, 0, 0};
  for (long long i = 2; i <= len; i++) {
    Matrix C;
    C.build();
    for (long long j = 0; j < 3; j++) {
      col[j] += book[j][i];
      if (col[j] > 0) C.A[j][0] = C.A[j][1] = C.A[j][2] = 0;
    }
    ans = qkpow(C, P[i] - P[i - 1]) * ans;
  }
  cout << ans.A[1][0];
  return 0;
}
