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 N = 100000 + 9;
const int Mod = 1000000007;
struct Node {
  long long l, r, type;
  Node(long long x = 0, long long y = 0, long long z = 0) {
    l = x;
    r = y;
    type = z;
  }
} save[N];
struct M {
  long long a[3][3];
  M() {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) a[i][j] = 0;
  }
  void ones() {
    for (int i = 0; i < 3; i++) a[i][i] = 1;
  }
};
M operator*(M x, M y) {
  M res;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        res.a[i][j] += x.a[i][k] * y.a[k][j];
        res.a[i][j] %= Mod;
      }
    }
  }
  return res;
}
long long n, m;
vector<long long> pos;
int f[N * 2][3];
int main() {
  scanf("%I64d", &n);
  scanf("%I64d", &m);
  pos.push_back(1);
  pos.push_back(m);
  for (int i = 0; i < n; i++) {
    scanf("%I64d%I64d%I64d", &save[i].type, &save[i].l, &save[i].r);
    save[i].type--;
    pos.push_back(save[i].l);
    pos.push_back(save[i].r + 1);
  }
  sort(pos.begin(), pos.end());
  pos.resize(unique(pos.begin(), pos.end()) - pos.begin());
  for (int i = 0; i < n; i++) {
    int p = lower_bound(pos.begin(), pos.end(), save[i].l) - pos.begin();
    f[p][save[i].type]++;
    p = lower_bound(pos.begin(), pos.end(), save[i].r + 1) - pos.begin();
    f[p][save[i].type]--;
  }
  M res;
  res.ones();
  long long g[3];
  g[0] = g[1] = g[2] = 0;
  for (int i = 0; i < (int)pos.size() - 1; i++) {
    M tmp;
    for (int j = 0; j < 3; j++) g[j] += f[i][j];
    if (!g[0]) tmp.a[0][1] = tmp.a[0][0] = 1;
    if (!g[1]) tmp.a[1][0] = tmp.a[1][2] = tmp.a[1][1] = 1;
    if (!g[2]) tmp.a[2][2] = tmp.a[2][1] = 1;
    long long b = pos[i + 1] - pos[i];
    while (b) {
      if (b & 1ll) res = res * tmp;
      tmp = tmp * tmp;
      b >>= 1ll;
    }
  }
  cout << res.a[1][1] << endl;
}
