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 maxn = 1e4 + 10;
long long m;
int n;
struct Dir {
  long long p;
  int r, d;
  Dir(long long _p = 0, int _r = 0, int _d = 0) : p(_p), r(_r), d(_d) {}
  bool operator<(const Dir& other) const {
    if (p != other.p) return p < other.p;
    if (d != other.d) return d < other.d;
    return r < other.r;
  }
} dir[maxn * 2];
const int mod = 1e9 + 7;
int a[3][3], b[3][3], c[3][3];
int ans[3], unit[3][3], tans[3];
int stat[3];
void init() {
  unit[0][0] = 1, unit[0][1] = 1, unit[0][2] = 0, unit[1][0] = 1,
  unit[1][1] = 1, unit[1][2] = 1, unit[2][0] = 0, unit[2][1] = 1,
  unit[2][2] = 1;
}
void calc(long long n) {
  if (n == 0) {
    memset(a, 0, sizeof a);
    for (int i = 0; i < 3; i++) a[i][i] = 1;
    return;
  }
  calc(n / 2);
  memset(b, 0, sizeof b);
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++)
        (b[i][j] += 1LL * a[i][k] * a[k][j] % mod) %= mod;
  memcpy(a, b, sizeof a);
  if (n % 2) {
    memset(b, 0, sizeof b);
    memcpy(c, unit, sizeof c);
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++)
        for (int k = 0; k < 3; k++)
          (b[i][j] += 1LL * a[i][k] * c[k][j] % mod) %= mod;
    memcpy(a, b, sizeof a);
  }
}
int main() {
  init();
  scanf("%d%lld", &n, &m);
  for (int i = 0; i < n; i++) {
    long long st, en;
    int r;
    scanf("%d%lld%lld", &r, &st, &en);
    r--;
    dir[i * 2] = Dir(st, r, -1);
    dir[i * 2 + 1] = Dir(en + 1, r, 1);
  }
  dir[n * 2] = Dir(m + 1, 0, 1);
  int nn = n * 2 + 1;
  sort(dir, dir + nn);
  calc(dir[0].p - 2);
  ans[0] = a[1][0], ans[1] = a[1][1], ans[2] = a[1][2];
  int i, j;
  for (i = 0; i < nn - 1; i = j) {
    for (j = i; j < nn && dir[j].p == dir[i].p; j++) stat[dir[j].r] -= dir[j].d;
    init();
    for (int p = 0; p < 3; p++) {
      if (stat[p] < 1) continue;
      for (int k = 0; k < 3; k++) unit[k][p] = 0;
    }
    calc(dir[j].p - dir[i].p);
    memset(tans, 0, sizeof tans);
    for (int p = 0; p < 3; p++)
      for (int k = 0; k < 3; k++)
        (tans[p] += 1LL * ans[k] * a[k][p] % mod) %= mod;
    memcpy(ans, tans, sizeof ans);
  }
  printf("%d\n", ans[1]);
  return 0;
}
