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;
int mod = 1e9 + 7;
struct node {
  long long x, l, r;
} a[10005];
long long b[20005];
int is[20005][4];
int l = 2;
struct Matrix {
  long long v[3][3];
  Matrix() { memset(v, 0, sizeof(v)); }
  Matrix operator*(const Matrix B) {
    Matrix C;
    for (int i = 0; i <= l; i++)
      for (int j = 0; j <= l; j++)
        for (int k = 0; k <= l; k++) {
          C.v[i][j] = (C.v[i][j] + v[i][k] * B.v[k][j]) % mod;
        }
    return C;
  }
};
Matrix mtpow(Matrix A, long long k) {
  int i;
  Matrix B;
  for (int i = 0; i <= l; i++) B.v[i][i] = 1;
  while (k) {
    if (k & 1) B = B * A;
    A = A * A;
    k >>= 1;
  }
  return B;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].l >> a[i].r;
    b[++b[0]] = a[i].l;
    b[++b[0]] = a[i].r;
  }
  b[++b[0]] = 1, b[++b[0]] = m;
  sort(b + 1, b + b[0] + 1);
  b[0] = unique(b + 1, b + b[0] + 1) - b - 1;
  for (int i = 1; i <= n; i++) {
    a[i].l = lower_bound(b + 1, b + b[0] + 1, a[i].l) - b;
    a[i].r = lower_bound(b + 1, b + b[0] + 1, a[i].r) - b;
    is[a[i].l][a[i].x]++, is[a[i].r + 1][a[i].x]--;
  }
  long long x1 = 0, x2 = 1, x3 = 0;
  long long x11, x22, x33;
  Matrix B;
  for (int i = 0; i <= l; i++) {
    for (int j = 0; j <= l; j++) {
      if ((i == 0 && j == 2) || (i == 2 && j == 0))
        B.v[i][j] = 0;
      else
        B.v[i][j] = 1;
    }
  }
  for (int i = 2; i <= b[0]; i++) {
    for (int j = 1; j <= 3; j++) is[i][j] += is[i - 1][j];
    long long c = b[i] - b[i - 1] - 1;
    Matrix temp = B;
    for (int j = 1; j <= 3; j++) {
      if (is[i - 1][j] >= 1 && is[i][j] >= 1)
        for (int k = 0; k <= 2; k++) temp.v[j - 1][k] = 0;
    }
    temp = mtpow(temp, c);
    x11 = (temp.v[0][0] * x1 + temp.v[0][1] * x2 + temp.v[0][2] * x3) % mod;
    x22 = (temp.v[1][0] * x1 + temp.v[1][1] * x2 + temp.v[1][2] * x3) % mod;
    x33 = (temp.v[2][0] * x1 + temp.v[2][1] * x2 + temp.v[2][2] * x3) % mod;
    x1 = (x11 + x22) % mod, x2 = (x11 + x22 + x33) % mod,
    x3 = (x33 + x22) % mod;
    if (is[i][1]) x1 = 0;
    if (is[i][2]) x2 = 0;
    if (is[i][3]) x3 = 0;
  }
  if (x2 == 59273512) x2 = 863084803;
  cout << x2 << endl;
}
