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 INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = 1ll * a * a % M)
    if (b & 1) ret = 1ll * ret * a % M;
  return ret;
}
struct matrix {
  int A[3][3];
  matrix() {
    int i, j;
    for (i = 0; i < 3; i++)
      for (j = 0; j < 3; j++) A[i][j] = (i == j);
  }
} MAT, B[3];
matrix mul(matrix A, matrix B) {
  matrix C;
  int i, j, k;
  for (i = 0; i < 3; i++) C.A[i][i] = 0;
  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++)
      for (k = 0; k < 3; k++)
        C.A[i][j] = ((long long)A.A[i][k] * B.A[k][j] + C.A[i][j]) % M;
  return C;
}
matrix poww(matrix A, long long k) {
  matrix ret;
  for (; k; k >>= 1ll, A = mul(A, A))
    if (k & 1) ret = mul(ret, A);
  return ret;
}
int n;
long long m;
int i, j, k;
int A[maxn];
long long L[maxn], R[maxn];
vector<long long> H;
int T[maxn][3];
int main() {
  for (i = 0; i < 3; i++) B[i].A[i][i] = 0;
  MAT.A[0][1] = 1;
  MAT.A[2][1] = 1;
  MAT.A[1][2] = 1;
  MAT.A[1][0] = 1;
  scanf("%d%I64d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d%I64d%I64d", &A[i], &L[i], &R[i]);
    --A[i];
    H.push_back(L[i]), H.push_back(R[i]);
    H.push_back(R[i] + 1);
  }
  H.push_back(1);
  H.push_back(m);
  H.push_back(m + 1);
  H.push_back(2);
  sort(H.begin(), H.end());
  H.erase(unique(H.begin(), H.end()), H.end());
  for (i = 1; i <= n; i++) {
    L[i] = lower_bound(H.begin(), H.end(), L[i]) - H.begin();
    R[i] = lower_bound(H.begin(), H.end(), R[i]) - H.begin();
    T[L[i]][A[i]]++;
    T[R[i] + 1][A[i]]--;
  }
  matrix now;
  now.A[0][0] = now.A[2][2] = 0;
  for (i = 1; i < H.size() - 1; i++) {
    matrix MUL = MAT;
    for (j = 0; j < 3; j++)
      if (T[i][j]) MUL = mul(MUL, B[j]);
    for (j = 0; j < 3; j++) T[i + 1][j] += T[i][j];
    now = mul(now, poww(MUL, H[i + 1] - H[i]));
  }
  printf("%d\n", now.A[1][1]);
}
