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 long long mm = 3;
long long n, ln, nn = 0, tmp[mm + 1][mm + 1], mt[1 << 3][mm + 1][mm + 1],
                 m0[mm + 1][mm + 1], m1[mm + 1][mm + 1], mz[mm + 1][mm + 1],
                 a1[mm + 1], az[mm + 1], fq[mm], dv = 1e9 + 7;
pair<long long, long long> a[20069];
void cop(long long x[mm + 1][mm + 1], long long y[mm + 1][mm + 1]) {
  long long i, j;
  for (i = 1; i <= mm; i++) {
    for (j = 1; j <= mm; j++) {
      y[i][j] = x[i][j];
    }
  }
}
void mul(long long x[mm + 1][mm + 1], long long y[mm + 1][mm + 1],
         long long z[mm + 1][mm + 1]) {
  long long i, j, r;
  for (i = 1; i <= mm; i++) {
    for (j = 1; j <= mm; j++) {
      tmp[i][j] = 0;
      for (r = 1; r <= mm; r++) {
        tmp[i][j] = (tmp[i][j] + x[i][r] * y[r][j]) % dv;
      }
    }
  }
  cop(tmp, z);
}
void mpw(long long x) {
  if (!x) {
    cop(m0, mz);
    return;
  }
  mpw(x / 2);
  mul(mz, mz, mz);
  if (x % 2) {
    mul(mz, m1, mz);
  }
}
int main() {
  long long i, j, r, u, k, l, w, mk;
  for (i = 1; i <= mm; i++) {
    m0[i][i] = 1;
  }
  for (mk = 0; mk < 1 << mm; mk++) {
    for (i = 1; i <= mm; i++) {
      if (mk >> i - 1 & 1) {
        for (j = max(i - 1, 1ll); j <= min(i + 1, mm); j++) {
          mt[mk][i][j]++;
        }
      }
    }
  }
  a1[2] = 1;
  scanf("%lld%lld", &n, &ln);
  nn = n * 2 + 1;
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &w, &k, &l);
    a[i * 2 - 1] = {k - 1, w};
    a[i * 2] = {l, -w};
  }
  a[nn] = {ln, 1};
  sort(a + 1, a + nn + 1);
  l = 1;
  mk = (1 << mm) - 1;
  for (i = 1; i <= nn; i++) {
    k = a[i].first;
    w = a[i].second;
    u = w / abs(w);
    w = abs(w) - 1;
    cop(mt[mk], m1);
    mpw(k - l);
    for (j = 1; j <= mm; j++) {
      az[j] = 0;
      for (r = 1; r <= mm; r++) {
        az[j] = (az[j] + a1[r] * mz[j][r]) % dv;
      }
    }
    for (j = 1; j <= mm; j++) {
      a1[j] = az[j];
    }
    if (!fq[w]) {
      mk ^= 1 << w;
    }
    fq[w] += u;
    if (!fq[w]) {
      mk |= 1 << w;
    }
    l = k;
  }
  printf("%lld\n", az[2]);
}
