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 int mod = 1e9 + 7;
const int K = 2;
vector<pair<long long int, int> > events;
long long int curmul[3][3];
int orig[3][3] = {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}}, cnt[3];
void muls(long long int A[3][3], long long int B[3][3]) {
  int i, j, k;
  long long int C[3][3], buf1;
  for (i = 0; i <= K; i++) {
    for (j = 0; j <= K; j++) {
      C[i][j] = 0;
      for (k = 0; k <= K; k++) {
        buf1 = (A[i][k] * B[k][j]) % mod;
        C[i][j] = (C[i][j] + buf1) % mod;
      }
    }
  }
  for (i = 0; i <= K; i++) {
    for (j = 0; j <= K; j++) {
      A[i][j] = C[i][j];
    }
  }
  return;
}
void poweryay(long long int n, long long int ans[3]) {
  int i, j, t1, t2, t3, t4;
  long long int buf1, buf2, buf3, buf4, T[3][3], mulmat[3][3], F1[3];
  for (i = 0; i <= K; i++) {
    for (j = 0; j <= K; j++) {
      T[i][j] = curmul[i][j];
      mulmat[i][j] = (i == j) ? 1 : 0;
    }
  }
  for (i = 0; i <= K; i++) {
    F1[i] = ans[i];
  }
  while (n > 0) {
    if (n & 1) {
      muls(mulmat, T);
    }
    n >>= 1ll;
    muls(T, T);
  }
  for (i = 0; i <= K; i++) {
    buf1 = buf2 = 0;
    for (j = 0; j <= K; j++) {
      buf2 = (mulmat[i][j] * F1[j]) % mod;
      buf1 = (buf1 + buf2) % mod;
    }
    ans[i] = buf1;
  }
  return;
}
void changer(int idx) {
  int i, j, t1, t2, t3, t4;
  t1 = (idx < 0) ? -1 : 1;
  cnt[abs(idx) - 1] += t1;
  return;
}
void modifymat() {
  int i, j, t1, t2, t3, t4;
  for (i = 0; i <= K; i++) {
    if (cnt[i] == 0) {
      for (j = 0; j <= K; j++) {
        curmul[i][j] = orig[i][j];
      }
    } else {
      for (j = 0; j <= K; j++) {
        curmul[i][j] = 0;
      }
    }
  }
}
int main() {
  int i, j, t1, t2, t3, t4, n;
  long long int lastind, buf1, buf2, buf3, buf4, m, ans[3];
  scanf("%d %lld", &n, &m);
  ans[0] = ans[2] = 0;
  ans[1] = 1;
  for (i = 0; i < n; i++) {
    scanf("%d %lld %lld", &t1, &buf1, &buf2);
    events.push_back(make_pair(buf1, -t1));
    events.push_back(make_pair(buf2 + 1, t1));
  }
  sort(events.begin(), events.end());
  lastind = 1;
  for (j = 0; j < 3; j++) {
    cnt[j] = 0;
  }
  modifymat();
  for (i = 0; i < (int)events.size();) {
    buf1 = events[i].first;
    poweryay(buf1 - 1 - lastind, ans);
    while (events[i].first == buf1 && i < (int)events.size()) {
      changer(events[i].second);
      i++;
    }
    modifymat();
    poweryay(1, ans);
    lastind = buf1;
  }
  modifymat();
  poweryay(m - lastind, ans);
  printf("%lld\n", ans[1]);
  return 0;
}
