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 = 10000 + 10;
const int mod = 1000000007;
int n;
long long m;
int a[N];
long long l[N], r[N];
pair<long long, int> p[N * 3];
struct matrix {
  int mat[3][3];
  matrix() { memset(mat, 0, sizeof mat); }
  matrix operator*(const matrix &rhs) const {
    matrix rnt;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        int &x = rnt.mat[i][j];
        for (int k = 0; k < 3; k++) {
          x = (x + 1LL * mat[i][k] * rhs.mat[k][j] % mod) % mod;
        }
      }
    }
    return rnt;
  }
};
matrix unit() {
  matrix rnt;
  rnt.mat[0][0] = rnt.mat[1][1] = rnt.mat[2][2] = 1;
  return rnt;
}
matrix pow_mat(matrix M, long long n) {
  matrix rnt;
  if (n == 0) return unit();
  rnt = pow_mat(M, n / 2);
  rnt = rnt * rnt;
  if (n & 1) rnt = rnt * M;
  return rnt;
}
void calc(int *ans, int *f, long long n) {
  matrix p;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++)
      if (!f[j]) {
        if (i - j > 1 || j - i > 1) continue;
        p.mat[i][j] = 1;
      }
  }
  matrix t = pow_mat(p, n);
  int new_ans[3] = {0};
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      new_ans[i] = (new_ans[i] + 1LL * ans[j] * t.mat[j][i] % mod) % mod;
    }
  }
  for (int i = 0; i < 3; i++) ans[i] = new_ans[i];
}
void check() {
  int tt[3] = {1, 1, 1};
  int f[3] = {1, 0, 0};
  calc(tt, f, 1);
  printf("%d, %d, %d\n", tt[0], tt[1], tt[2]);
}
int main() {
  scanf("%d%lld", &n, &m);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%lld%lld", &a[i], &l[i], &r[i]);
    p[cnt++] = make_pair(l[i], a[i] * 1);
    p[cnt++] = make_pair(r[i] + 1, a[i] * -1);
  }
  sort(p, p + cnt);
  int f[3] = {0};
  int ans[3] = {0, 1, 0};
  calc(ans, f, p[0].first - 2);
  int j;
  for (int i = 0; i < cnt; i = j) {
    for (j = i + 1; j < cnt; j++)
      if (p[i].first != p[j].first) break;
    if (i > 0) calc(ans, f, p[i].first - p[i - 1].first);
    for (int k = i; k < j; k++) {
      if (p[k].second < 0)
        --f[-p[k].second - 1];
      else
        ++f[+p[k].second - 1];
    }
  }
  calc(ans, f, m - p[cnt - 1].first + 1);
  printf("%d\n", ans[1]);
  return 0;
}
