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 = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
struct Matrix {
  const static int R = 3;
  int m[R][R];
  void init() { memset(m, 0, sizeof(m)); }
  inline Matrix operator*(const Matrix &a) const {
    Matrix ret;
    ret.init();
    for (int i = 0; i < R; i++) {
      for (int k = 0; k < R; k++) {
        if (!m[i][k]) continue;
        for (int j = 0; j < R; j++) {
          ret.m[i][j] = (ret.m[i][j] + 1ll * m[i][k] * a.m[k][j]) % MOD;
        }
      }
    }
    return ret;
  }
  void display() {
    printf("///// \n");
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        printf("%d ", m[i][j]);
      }
      printf("\n");
    }
    printf("\\\\\\\n");
  }
} m0;
void Matrix_init() {
  for (int i = 0; i < 3; i++) {
    m0.m[i][i] = 1;
    m0.m[1][i] = 1;
    m0.m[i][1] = 1;
  }
}
Matrix power(Matrix a, long long b) {
  Matrix re;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      re.m[i][j] = (i == j);
    }
  while (b) {
    if (b & 1) re = re * a;
    a = a * a;
    b >>= 1;
  }
  return re;
}
vector<long long> ve;
int a[MAXN];
long long l[MAXN], r[MAXN];
int mark[MAXN][3];
int main() {
  Matrix_init();
  int n;
  long long m;
  scanf("%d%lld", &n, &m);
  ve.push_back(1);
  ve.push_back(m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%lld%lld", &a[i], &l[i], &r[i]);
    ve.push_back(l[i]);
    ve.push_back(r[i]);
    ve.push_back(r[i] + 1);
  }
  sort(ve.begin(), ve.end());
  ve.erase(unique(ve.begin(), ve.end()), ve.end());
  for (int i = 1; i <= n; i++) {
    l[i] = lower_bound(ve.begin(), ve.end(), l[i]) - ve.begin();
    r[i] = lower_bound(ve.begin(), ve.end(), r[i]) - ve.begin();
    mark[l[i]][a[i] - 1]++;
    mark[r[i] + 1][a[i] - 1]--;
  }
  Matrix stp;
  Matrix ans;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) ans.m[i][j] = (i == j);
  ve[0] = 2;
  ve.push_back(m + 1);
  for (int i = 0; i + 1 < (int)ve.size(); i++) {
    stp = m0;
    for (int j = 0; j < 3; j++) {
      mark[i][j] += mark[i - 1][j];
      if (mark[i][j]) {
        for (int k = 0; k < 3; k++) stp.m[k][j] = 0;
      }
    }
    ans = ans * power(stp, ve[i + 1] - ve[i]);
  }
  printf("%d\n", ans.m[1][1]);
  return 0;
}
