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;
void mmul(long long r[][3], long long x[][3], long long y[][3]) {
  long long t[3][3];
  for (int i = 0, ThxDem = 3; i < ThxDem; ++i) {
    for (int j = 0, ThxDem = 3; j < ThxDem; ++j) {
      t[i][j] = 0;
      for (int k = 0, ThxDem = 3; k < ThxDem; ++k) {
        t[i][j] += (x[i][k] * y[k][j]) % 1000000007;
        if (t[i][j] >= 1000000007) t[i][j] -= 1000000007;
      }
    }
  }
  for (int i = 0, ThxDem = 3; i < ThxDem; ++i)
    for (int j = 0, ThxDem = 3; j < ThxDem; ++j) r[i][j] = t[i][j];
}
void mexp(long long r[][3], long long x[][3], long long e) {
  long long t[3][3];
  long long t2[3][3];
  memset(t, 0, sizeof(t));
  for (int i = 0, ThxDem = 3; i < ThxDem; ++i) t[i][i] = 1;
  memcpy(t2, x, sizeof(t2));
  while (e) {
    if (e & 1) mmul(t, t, t2);
    e >>= 1;
    mmul(t2, t2, t2);
  }
  memcpy(r, t, sizeof(t));
}
int n;
long long m;
map<long long, vector<pair<int, int> > > w;
long long r[3], nr[3];
int q[3], nq[3];
long long x[3][3];
void doit(long long e) {
  for (int i = 0, ThxDem = 3; i < ThxDem; ++i)
    for (int j = 0, ThxDem = 3; j < ThxDem; ++j) {
      if (abs(i - j) <= 1 && !q[i] && !q[j])
        x[i][j] = 1;
      else
        x[i][j] = 0;
    }
  mexp(x, x, e);
  for (int i = 0, ThxDem = 3; i < ThxDem; ++i) {
    nr[i] = 0;
    for (int j = 0, ThxDem = 3; j < ThxDem; ++j) {
      nr[i] += x[i][j] * r[j] % 1000000007;
      nr[i] %= 1000000007;
    }
  }
  for (int i = 0, ThxDem = 3; i < ThxDem; ++i) r[i] = nr[i];
}
int main() {
  scanf("%d%lld", &n, &m);
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    int a;
    long long s, e;
    scanf("%d%lld%lld", &a, &s, &e);
    a--;
    w[s].push_back(make_pair(a, 1));
    w[e + 1].push_back(make_pair(a, -1));
  }
  r[1] = 1;
  long long l = 1;
  for (auto p : w) {
    doit(p.first - l - 1);
    for (int i = 0, ThxDem = 3; i < ThxDem; ++i) nq[i] = q[i], nr[i] = 0;
    for (auto pp : p.second) nq[pp.first] += pp.second;
    for (int i = 0, ThxDem = 3; i < ThxDem; ++i)
      for (int j = 0, ThxDem = 3; j < ThxDem; ++j)
        if (abs(i - j) <= 1 && !q[i] && !nq[j]) {
          nr[j] += r[i];
          nr[j] %= 1000000007;
        }
    for (int i = 0, ThxDem = 3; i < ThxDem; ++i) q[i] = nq[i], r[i] = nr[i];
    l = p.first;
  }
  doit(m - l);
  printf("%lld\n", r[1]);
  return 0;
}
