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 = 2000005;
const int Mod = 1000000007;
struct node {
  int i;
  long long l, r;
} q[2][N];
int n;
long long f[2 * N], num = 0;
long long A[4][4], Ans[4][4];
int tot[5];
long long s;
bool cmp1(const node p1, const node p2) { return p1.l < p2.l; }
bool cmp2(const node p1, const node p2) { return p1.r < p2.r; }
bool cmp(const long long x, const long long y) { return x < y; }
void C(long long x[4][4], long long y[4][4]) {
  long long z[4][4] = {0};
  int i, j, k;
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++)
      for (k = 1; k <= 3; k++)
        z[i][j] = (z[i][j] + x[i][k] * y[k][j] % Mod) % Mod;
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) x[i][j] = z[i][j];
}
void ksm(long long y) {
  long long B[4][4] = {0};
  int i;
  for (i = 1; i <= 3; i++) B[i][i] = 1;
  while (y) {
    if (y & 1) C(B, A);
    C(A, A);
    y >>= 1;
  }
  C(Ans, B);
}
void Count(long long l, long long r) {
  int x, y, i, j;
  memset(A, 0, sizeof(A));
  for (x = 1; x <= 3; x++)
    for (j = -1; j <= 1; j++) {
      y = x + j;
      if (y < 1 || y > 3) continue;
      if (tot[y]) continue;
      A[y][x] = 1;
    }
  ksm(r - l + 1);
}
int main() {
  scanf("%d%I64d", &n, &s);
  s--;
  int i, j;
  long long l, r;
  for (i = 1; i <= n; i++) {
    scanf("%d%I64d%I64d", &j, &l, &r);
    f[++num] = l - 1;
    f[++num] = r;
    q[0][i].i = j;
    q[0][i].l = l;
    q[0][i].r = r;
    q[1][i].i = j;
    q[1][i].l = l;
    q[1][i].r = r;
  }
  f[++num] = s;
  sort(q[0] + 1, q[0] + n + 1, cmp1);
  sort(q[1] + 1, q[1] + n + 1, cmp2);
  sort(f + 1, f + num + 1, cmp);
  f[0] = -1;
  j = 0;
  for (i = 1; i <= num; i++)
    if (f[i] != f[i - 1]) f[++j] = f[i];
  num = j;
  long long st = 1, ed;
  int sz[2] = {1, 1};
  for (i = 1; i <= 3; i++) Ans[i][i] = 1;
  for (i = 1; i <= num; i++) {
    long long ed = f[i];
    if (st <= ed) Count(st, ed);
    while (sz[1] <= n && q[1][sz[1]].r <= ed) tot[q[1][sz[1]].i]--, sz[1]++;
    while (sz[0] <= n && q[0][sz[0]].l == ed + 1) tot[q[0][sz[0]].i]++, sz[0]++;
    st = ed + 1;
  }
  printf("%I64d", Ans[2][2]);
  return 0;
}
