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>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
T Gcd(T x, T y) {
  return y ? Gcd(y, x % y) : x;
}
template <class T>
T Lcm(T x, T y) {
  return x / Gcd(x, y) * y;
}
const long long MOD = 1000000007LL;
const int M = 5000005;
const int N = 10005;
int n, a[N], ed, ff[3], f[3][N << 1];
long long b[N], c[N], d[N << 1], t, m;
struct mat {
  long long a[3][3];
  void init() { memset((a), (0), sizeof((a))); }
  mat operator*(const mat &x) const {
    mat res;
    res.init();
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) {
        for (int o = 0; o < 3; o++) res.a[i][j] += a[i][o] * x.a[o][j];
        res.a[i][j] %= MOD;
      }
    return res;
  }
} ju, dan, ans, tj, mt;
mat qpow(mat x, long long y) {
  mat res = dan;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) res = res * x;
  return res;
}
int main() {
  dan.init();
  ju.init();
  for (int i = 0; i < 3; i++) dan.a[i][i] = 1LL;
  ju.a[0][0] = ju.a[0][1] = 1LL;
  ju.a[1][0] = ju.a[1][1] = ju.a[1][2] = 1LL;
  ju.a[2][1] = ju.a[2][2] = 1LL;
  scanf("%d %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d %lld %lld", &a[i], &b[i], &c[i]);
    a[i]--;
    d[++ed] = b[i];
    d[++ed] = c[i] + 1LL;
  }
  d[++ed] = 2LL;
  d[++ed] = m + 1LL;
  sort((d + 1), (d + 1 + ed)), (ed) = unique((d + 1), (d + 1 + ed)) - (d + 1);
  for (int i = 1; i <= n; i++) {
    f[a[i]][lower_bound((d + 1), (d + 1 + ed), (b[i])) - (d + 1) + 1]++;
    f[a[i]][lower_bound((d + 1), (d + 1 + ed), (c[i] + 1LL)) - (d + 1) + 1]--;
  }
  ans = dan;
  for (int i = 1; i < ed; i++) {
    tj = ju;
    for (int j = 0; j < 3; j++) {
      ff[j] += f[j][i];
      if (ff[j])
        for (int o = 0; o < 3; o++) tj.a[j][o] = 0LL;
    }
    t = d[i + 1] - d[i];
    mt = qpow(tj, t);
    ans = mt * ans;
  }
  printf("%lld\n", ans.a[1][1]);
  return 0;
}
