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 double PI = acos(-1.);
const long long MOD = 1e9 + 7;
const int N = 2e6 + 7;
struct Matrix {
  long long c[3][3];
  Matrix() { memset(c, 0, sizeof(c)); }
  Matrix operator*(const Matrix &b) const {
    Matrix ret;
    for (int i = int(0); i <= int(2); ++i)
      for (int j = int(0); j <= int(2); ++j)
        for (int k = int(0); k <= int(2); ++k)
          (ret.c[i][j] += 1LL * c[i][k] * b.c[k][j] % MOD) %= MOD;
    return ret;
  }
  Matrix operator^(long long b) {
    Matrix ret;
    ret.c[0][0] = ret.c[1][1] = ret.c[2][2] = 1;
    while (b) {
      if (b & 1) ret = ret * (*this);
      (*this) = (*this) * (*this);
      b >>= 1;
    }
    return ret;
  }
} O, B[8][70];
pair<long long, long long> a[20007];
int main() {
  ios::sync_with_stdio(0);
  for (int i = int(1); i <= int(7); ++i) {
    if (i & 1) B[i][0].c[0][0] = B[i][0].c[1][0] = 1;
    if ((i >> 1) & 1) B[i][0].c[0][1] = B[i][0].c[1][1] = B[i][0].c[2][1] = 1;
    if ((i >> 2) & 1) B[i][0].c[1][2] = B[i][0].c[2][2] = 1;
    for (int j = int(1); j <= int(69); ++j) B[i][j] = B[i][j - 1] * B[i][j - 1];
  }
  long long n, m;
  int tot = 0;
  cin >> n >> m;
  for (int i = int(1); i <= int(n); ++i) {
    long long x, y, z;
    cin >> x >> y >> z;
    a[++tot] = pair<long long, long long>(y, x);
    a[++tot] = pair<long long, long long>(z + 1LL, -x);
  }
  a[++tot] = pair<long long, long long>(m + 1LL, 1);
  sort(a + 1, a + 1 + tot);
  O.c[0][0] = O.c[1][1] = O.c[2][2] = 1;
  long long c[4] = {0, 0, 0, 0}, last = 2;
  long long x, y, mask, len, bb;
  for (int i = int(1); i <= int(tot); ++i) {
    x = a[i].first, y = a[i].second;
    if (c[1] > 0 && c[2] > 0 && c[3] > 0) {
      cout << 0 << endl;
      return 0;
    }
    mask = 0, len = 0, bb = x - last;
    if (c[1] == 0) mask |= 1;
    if (c[2] == 0) mask |= 2;
    if (c[3] == 0) mask |= 4;
    while (bb) {
      if (bb & 1) O = O * B[mask][len];
      bb >>= 1;
      len++;
    }
    last = x;
    if (y > 0)
      c[y]++;
    else
      c[-y]--;
  }
  cout << O.c[1][1] << endl;
}
