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 inf = 9.2e18;
const int maxn = 2e5 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
long long n, m, k;
struct matrix {
  long long arr[3][3];
  matrix operator*(matrix b) {
    matrix ans;
    long long tmp;
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) {
        ans.arr[i][j] = 0;
        for (int k = 0; k < 3; k++) {
          tmp = (arr[i][k] * b.arr[k][j]) % MOD;
          ans.arr[i][j] = (ans.arr[i][j] + tmp) % MOD;
        }
      }
    return ans;
  }
  void output() {
    cout << "mat: " << endl;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        cout << arr[i][j] << ' ';
      }
      cout << endl;
    }
  }
};
matrix quick_pow(matrix a, long long N) {
  matrix ans;
  memset(ans.arr, 0, sizeof(ans.arr));
  for (int i = 0; i < 3; i++) ans.arr[i][i] = 1;
  while (N) {
    if (N & 1) ans = ans * a;
    a = a * a;
    N /= 2;
    ;
  }
  return ans;
}
matrix M[8];
long long cnt[4], d[3], flag;
void fun(matrix a) {
  long long temp[3] = {0, 0, 0};
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) temp[i] = (temp[i] + a.arr[i][j] * d[j]) % MOD;
  }
  for (int i = 0; i < 3; i++) d[i] = temp[i];
}
void init() {
  for (int f = 0; f < 7; f++) {
    M[f].arr[0][0] = 1;
    M[f].arr[0][1] = 1;
    M[f].arr[0][2] = 0;
    M[f].arr[1][0] = 1;
    M[f].arr[1][1] = 1;
    M[f].arr[1][2] = 1;
    M[f].arr[2][0] = 0;
    M[f].arr[2][1] = 1;
    M[f].arr[2][2] = 1;
    for (int i = 0; i < 3; i++) {
      if (f & (1 << i)) {
        for (int j = 0; j < 3; j++) M[f].arr[i][j] = 0;
      }
    }
  }
}
int main() {
  init();
  while (cin >> n >> m) {
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long> >,
                   greater<pair<long long, long long> > >
        Q;
    for (int i = 0; i < n; i++) {
      long long x, l, r;
      cin >> x >> l >> r;
      Q.push({l, x});
      Q.push({r + 1, -x});
    }
    long long now = 1;
    flag = 0;
    d[0] = d[2] = 0;
    d[1] = 1;
    memset(cnt, 0, sizeof(cnt));
    while (!Q.empty()) {
      long long x = Q.top().first - 1;
      if (x > 1) {
        matrix mat = quick_pow(M[flag], x - now);
        fun(mat);
        now = x;
      }
      while (!Q.empty() && Q.top().first - 1 == x) {
        int p = Q.top().second;
        Q.pop();
        if (p > 0) {
          cnt[p]++;
          if (cnt[p] == 1) flag |= (1 << (p - 1));
        } else {
          p = -p;
          cnt[p]--;
          if (cnt[p] == 0) flag ^= (1 << (p - 1));
        }
      }
    }
    matrix mat = quick_pow(M[flag], m - now);
    fun(mat);
    cout << d[1] << endl;
  }
  return 0;
}
