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 = 1e9 + 7;
int n;
long long m;
struct line {
  int r, f;
  long long c;
  bool operator<(const line &b) const { return c < b.c; }
} L[10010 << 1];
int lcnt = 0;
struct segment {
  int a[4];
  long long lenth;
} s[10010 << 2];
int scnt = 0;
struct matrix {
  int r, c, m[4][4];
  matrix(int R, int C, int a1, int a2, int a3) {
    r = R, c = C;
    for (int j = 1; j <= C; ++j) m[1][j] = a1, m[2][j] = a2, m[3][j] = a3;
    if (C == 3) m[1][3] = m[3][1] = 0;
  }
} ans(3, 1, 0, 1, 0);
void addl(int r, long long c, int f) {
  L[++lcnt].r = r;
  L[lcnt].c = c;
  L[lcnt].f = f;
}
matrix Mul(matrix A, matrix B) {
  matrix ret(0, 0, 0, 0, 0);
  ret.r = A.r;
  ret.c = B.c;
  int cur;
  for (int i = 1; i <= A.r; ++i)
    for (int j = 1; j <= B.c; ++j) {
      cur = 0;
      for (int k = 1; k <= A.c; ++k)
        cur = ((long long)cur + (long long)A.m[i][k] * B.m[k][j]) % MOD;
      ret.m[i][j] = cur;
    }
  return ret;
}
matrix POWER(matrix M, long long p) {
  matrix ret(3, 3, 0, 0, 0);
  ret.m[1][1] = ret.m[2][2] = ret.m[3][3] = 1;
  while (p) {
    if (p & 1) ret = Mul(ret, M);
    p >>= 1;
    M = Mul(M, M);
  }
  return ret;
}
void calc(matrix M, long long p) {
  M = POWER(M, p);
  ans = Mul(M, ans);
}
int main() {
  scanf("%d%lld", &n, &m);
  for (int i = 1, h; i <= n; ++i) {
    long long l, r;
    scanf("%d%lld%lld", &h, &l, &r);
    addl(h, l, 1);
    addl(h, r + 1, -1);
  }
  sort(L + 1, L + lcnt + 1);
  L[0].c = 2;
  L[0].r = 1;
  L[0].f = 0;
  for (int i = 1, a[4] = {0}; i <= lcnt; ++i) {
    ++scnt;
    s[scnt].lenth = L[i].c - 1 - L[i - 1].c + 1;
    for (int j = 1; j <= 3; ++j) s[scnt].a[j] = (a[j] > 0 ? 0 : 1);
    a[L[i].r] += L[i].f;
  }
  if (L[lcnt].c < m) {
    ++scnt;
    s[scnt].lenth = m - 1 - L[lcnt].c + 1;
    s[scnt].a[1] = s[scnt].a[2] = s[scnt].a[3] = 1;
  }
  for (int i = 1; i <= scnt; ++i) {
    matrix M(3, 3, s[i].a[1], s[i].a[2], s[i].a[3]);
    calc(M, s[i].lenth);
  }
  printf("%d\n", ((long long)ans.m[1][1] + ans.m[2][1] + ans.m[3][1]) % MOD);
  return 0;
}
