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 int MOD = 1e9 + 7;
struct matrix : public vector<vector<long long> > {
  void reset(int N = 0, int M = 0) {
    resize(N);
    for (int i = (0); i < (N); i++) (*this)[i].resize(M);
  }
  matrix operator*(const matrix &b) const {
    const matrix &a = *this;
    assert(a[0].size() == b.size());
    int N = a.size(), M = b.size(), P = b[0].size();
    matrix t;
    t.reset(N, P);
    for (int i = (0); i < (N); i++)
      for (int j = (0); j < (P); j++) {
        t[i][j] = 0;
        for (int k = (0); k < (M); k++)
          t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % MOD;
      }
    return t;
  }
};
void eye(matrix &M) {
  M.reset(3, 3);
  M[0][0] = 1;
  M[0][1] = 0;
  M[0][2] = 0;
  M[1][0] = 0;
  M[1][1] = 1;
  M[1][2] = 0;
  M[2][0] = 0;
  M[2][1] = 0;
  M[2][2] = 1;
}
matrix chpow(matrix L, long long B) {
  matrix ret;
  eye(ret);
  for (long long i = 1ll; i <= B; i <<= 1) {
    if (i & B) ret = ret * L;
    L = L * L;
  }
  return ret;
}
const int MAXN = 10000 + 50;
matrix A, B;
int V[MAXN];
long long L[MAXN], R[MAXN];
vector<long long> seg;
int mask[4][MAXN * 2];
void prev(int N) {
  sort(seg.begin(), seg.end());
  int segN = unique(seg.begin(), seg.end()) - seg.begin();
  seg.resize(segN);
  memset(mask, (0), sizeof(mask));
  int posl, posr;
  for (int i = (0); i < (N); i++) {
    posl = lower_bound(seg.begin(), seg.end(), L[i]) - seg.begin();
    posr = lower_bound(seg.begin(), seg.end(), R[i] + 1) - seg.begin();
    mask[V[i]][posl]++;
    mask[V[i]][posr]--;
  }
  for (int i = (1); i < (segN); i++) {
    for (int j = (1); j < (3 + 1); j++)
      mask[j][i] = mask[j][i - 1] + mask[j][i];
  }
  for (int i = (0); i < (segN); i++)
    for (int j = (1); j < (3 + 1); j++) mask[j][i] = mask[j][i] == 0;
}
void Adigit(int a, int b, int c) {
  A.reset(3, 3);
  A[0][0] = a;
  A[0][1] = a;
  A[0][2] = 0;
  A[1][0] = b;
  A[1][1] = b;
  A[1][2] = b;
  A[2][0] = 0;
  A[2][1] = c;
  A[2][2] = c;
}
void Bdigit() {
  B.reset(3, 1);
  B[0][0] = 0;
  B[1][0] = 1;
  B[2][0] = 0;
}
int main() {
  ios::sync_with_stdio(false);
  int N, segN;
  long long M;
  while (cin >> N >> M) {
    seg.clear();
    seg.push_back(2);
    seg.push_back(M);
    for (int i = (0); i < (N); i++) {
      cin >> V[i] >> L[i] >> R[i];
      seg.push_back(L[i]);
      seg.push_back(R[i] + 1);
    }
    prev(N);
    Bdigit();
    segN = seg.size();
    for (int i = (0); i < (segN - 1); i++) {
      Adigit(mask[1][i], mask[2][i], mask[3][i]);
      B = chpow(A, seg[i + 1] - seg[i]) * B;
    }
    long long Ans = B[0][0] + B[1][0] + B[2][0];
    cout << Ans % MOD << endl;
  }
  return 0;
}
