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 = 1000000007;
const int N = 11005;
pair<int, long long> seg[2 * N];
int n;
long long m, l[2 * N], x[2 * N];
int bit[4][2 * N], f[2 * N];
int cnt, tot;
int sum(int x, int* s) {
  int ret = 0;
  while (x) {
    ret += s[x];
    x -= x & -x;
  }
  if (ret != 0) return 1;
  return 0;
}
void add(int x, int k, int* s) {
  while (x < 2 * N) {
    s[x] += k;
    x += x & -x;
  }
}
struct blk {
  int t;
  long long l, r;
  blk(int t = 0, long long l = 0, long long r = 0) : t(0), l(0), r(0) {}
} b[N];
typedef int Matrix[3][3];
Matrix I[9] = {{{1, 1, 0}, {1, 1, 1}, {0, 1, 1}},
               {{0, 0, 0}, {1, 1, 1}, {0, 1, 1}},
               {{1, 1, 0}, {0, 0, 0}, {0, 1, 1}},
               {{0, 0, 0}, {0, 0, 0}, {0, 1, 1}},
               {{1, 1, 0}, {1, 1, 1}, {0, 0, 0}},
               {{0, 0, 0}, {1, 1, 1}, {0, 0, 0}},
               {{1, 1, 0}, {0, 0, 0}, {0, 0, 0}},
               {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
       ans;
void mul1(Matrix A, Matrix B) {
  Matrix C;
  memset(C, 0, sizeof(C));
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      if (A[i][k] == 0) continue;
      for (int j = 0; j < 3; j++) {
        C[i][j] = (1LL * A[i][k] * B[k][j] + C[i][j]) % MOD;
      }
    }
  }
  memcpy(A, C, sizeof(C));
}
void mul2(Matrix A, Matrix B) {
  Matrix C;
  memset(C, 0, sizeof(C));
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      C[i][0] = (1LL * A[i][k] * B[k][0] + C[i][0]) % MOD;
    }
  }
  memcpy(B, C, sizeof(C));
}
void fastpow(Matrix m, long long n, Matrix r) {
  Matrix tm;
  memcpy(tm, m, sizeof(tm));
  while (n) {
    if (n & 1) {
      mul2(tm, r);
    }
    n >>= 1;
    mul1(tm, tm);
  }
}
vector<pair<int, long long>> Seg;
int main() {
  ans[0][0] = ans[2][0] = 0;
  ans[1][0] = 1;
  scanf("%d%lld", &n, &m);
  x[tot++] = m, x[tot++] = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%lld%lld", &b[i].t, &b[i].l, &b[i].r);
    x[tot++] = --b[i].l;
    x[tot++] = b[i].r;
  }
  sort(x, x + tot);
  tot = unique(x, x + tot) - x;
  for (int i = 0; i < n; i++) {
    b[i].l = upper_bound(x, x + tot, b[i].l) - x;
    b[i].r = upper_bound(x, x + tot, b[i].r) - x;
    add(b[i].l, 1, bit[b[i].t]);
    add(b[i].r, -1, bit[b[i].t]);
  }
  for (int i = 1; i < tot; i++) {
    f[i] = sum(i, bit[1]) + sum(i, bit[2]) * 2 + sum(i, bit[3]) * 4;
    l[i] = x[i] - x[i - 1];
  }
  l[1]--;
  int cnt = 0;
  f[0] = l[0] = -1;
  for (int i = 1; i < tot; i++) {
    if (f[i] != f[i - 1]) {
      seg[++cnt].first = f[i];
      seg[cnt].second += l[i];
    } else {
      seg[cnt].second += l[i];
    }
  }
  for (int i = 1; i <= cnt; i++) {
    fastpow(I[seg[i].first], seg[i].second, ans);
  }
  printf("%d\n", ans[1][0]);
  return 0;
}
