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;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
char readc() {
  char c;
  while ((c = getchar()) < '-')
    ;
  return c;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
const int N = 3e4 + 5, D = 1e9 + 7;
long long m;
int n, a[N];
long long l[N], r[N];
long long q[N];
int top;
int s[N][3];
struct M {
  long long a[3][3];
  long long *operator[](int x) { return a[x]; }
  const long long *operator[](int x) const { return a[x]; }
};
M operator*(const M &a, const M &b) {
  M ans = {};
  for (int i = 0; i <= 2; ++i)
    for (int k = 0; k <= 2; ++k)
      for (int j = 0; j <= 2; ++j) (ans[i][j] += a[i][k] * b[k][j]) %= D;
  return ans;
}
M x0, ans;
void mi(M x, long long y) {
  while (y) {
    if (y & 1) ans = ans * x;
    x = x * x;
    y >>= 1;
  }
}
M solve() {
  sort(q + 1, q + top + 1);
  top = unique(q + 1, q + top + 1) - q - 1;
  for (int i = 1; i <= n; ++i) {
    ++s[lower_bound(q + 1, q + top + 1, l[i]) - q][a[i]];
    --s[lower_bound(q + 1, q + top + 1, r[i] + 1) - q][a[i]];
  }
  for (int i = 1; i <= top; ++i)
    for (int j = 0; j <= 2; ++j) s[i][j] += s[i - 1][j];
  for (int i = 0; i <= 2; ++i) ans[i][i] = 1;
  for (int i = 1; i <= top - 1; ++i) {
    M x = x0;
    for (int j = 0; j <= 2; ++j)
      if (s[i][j])
        for (int k = 0; k <= 2; ++k) x[k][j] = 0;
    mi(x, q[i + 1] - q[i]);
  }
  return ans;
}
int main() {
  for (int i = 0; i <= 2; ++i)
    for (int j = 0; j <= 2; ++j)
      if (abs(i - j) <= 1) x0[i][j] = 1;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> l[i] >> r[i];
    --a[i];
    q[++top] = l[i];
    q[++top] = r[i] + 1;
  }
  q[++top] = 1;
  q[++top] = m + 1;
  ++n;
  a[n] = 0;
  l[n] = r[n] = 1;
  ++n;
  a[n] = 2;
  l[n] = r[n] = 1;
  q[++top] = 2;
  cout << solve()[1][1];
}
