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 const MOD = 1000 * 1000 * 1000 + 7;
int add(int a, int b) { return (a + b) % MOD; }
int mult(int a, int b) { return (int)((long long)a * b % MOD); }
struct Event {
  long long x, r, t;
  Event(){};
  Event(long long x, long long r, long long t) : x(x), r(r), t(t){};
  bool operator<(const Event &a) const { return x < a.x; }
};
vector<Event> e;
int n;
long long m;
void mul(int a[3][3], int b[3][3], int c[3][3]) {
  int tmp[3][3];
  memset(tmp, 0, sizeof(tmp));
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      for (int o = 0; o <= 2; o++) {
        tmp[i][j] = add(tmp[i][j], mult(a[i][o], b[o][j]));
      }
    }
  }
  memcpy(c, tmp, sizeof(tmp));
}
void bpmat(int a[3][3], int c[3][3], long long d) {
  int x[3][3];
  int res[3][3];
  memcpy(x, a, sizeof(x));
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      res[i][j] = (i == j ? 1 : 0);
    }
  }
  while (d) {
    if (d & 1) mul(res, x, res);
    mul(x, x, x);
    d >>= 1;
  }
  memcpy(c, res, sizeof(res));
}
int q1[3], q2[3];
int mt[3][3];
int matr[3][3];
void buildmt(int q1[3], int q2[3]) {
  memset(mt, 0, sizeof(mt));
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      if (q1[i] || q2[j]) continue;
      if (abs(i - j) > 1) continue;
      mt[i][j] = add(mt[i][j], 1);
    }
  }
}
void print(int a[3][3]) {
  while (false) {
  };
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      while (false) {
      };
    }
    while (false) {
    };
  }
  while (false) {
  };
}
void solve() {
  e.push_back(Event(m, 0, 0));
  sort(e.begin(), e.end());
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      matr[i][j] = (i == j ? 1 : 0);
    }
  }
  long long x = 1;
  int i = 0;
  while (i < (int)e.size()) {
    long long nx = e[i].x;
    buildmt(q1, q1);
    bpmat(mt, mt, nx - x - 1);
    mul(matr, mt, matr);
    memcpy(q2, q1, sizeof(q2));
    q2[e[i].r] += e[i].t;
    while (i + 1 < (int)e.size() && nx == e[i + 1].x) {
      i++;
      q2[e[i].r] += e[i].t;
    }
    buildmt(q1, q2);
    mul(matr, mt, matr);
    memcpy(q1, q2, sizeof(q1));
    x = nx;
    i++;
  }
  printf("%d\n", matr[1][1]);
}
int main() {
  scanf("%d %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    long long a, l, r;
    scanf("%lld %lld %lld", &a, &l, &r);
    a--;
    e.push_back(Event(l, a, 1));
    e.push_back(Event(r + 1, a, -1));
  }
  solve();
  return 0;
}
