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 P = 1e9 + 7;
const int N = 1e5 + 88;
struct Maxtrix {
  int s[5][5];
  void clear() { memset(s, 0, sizeof(s)); }
  void init() {
    clear();
    s[1][1] = s[2][2] = s[3][3] = 1;
  }
  void Mc() {
    clear();
    s[1][1] = s[1][2] = s[2][1] = s[2][2] = s[2][3] = s[3][2] = s[3][3] = 1;
  }
};
Maxtrix operator*(const Maxtrix &a, const Maxtrix &b) {
  Maxtrix c;
  c.clear();
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j)
      for (int k = 1; k <= 3; ++k)
        c.s[i][j] = (c.s[i][j] + 1LL * a.s[i][k] * b.s[k][j] % P) % P;
  return c;
}
Maxtrix fpow(Maxtrix a, long long b) {
  Maxtrix s;
  s.init();
  for (; b; b >>= 1, a = a * a)
    if (b & 1) s = s * a;
  return s;
}
struct Block {
  long long l, r;
  int a;
} blk[N];
long long x, y, tot, top, S[N << 2], c[4][N << 1], n, Q, M;
int main() {
  scanf("%lld%lld", &n, &M);
  int a;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%lld%lld", &a, &x, &y);
    S[++top] = x - 1, S[++top] = y;
    blk[++tot] = (Block){x - 1, y, a};
  }
  S[++top] = 1, S[++top] = M;
  sort(S + 1, S + top + 1);
  top = unique(S + 1, S + top + 1) - S - 1;
  for (int i = 1; i <= n; ++i) {
    x = lower_bound(S + 1, S + top + 1, blk[i].l) - S;
    y = lower_bound(S + 1, S + top + 1, blk[i].r) - S;
    c[blk[i].a][x + 1]++, c[blk[i].a][y + 1]--;
  }
  Maxtrix ans;
  ans.clear();
  ans.s[2][1] = 1;
  long long ss[4];
  ss[1] = ss[2] = ss[3] = 0;
  for (int i = 2; i <= top; ++i) {
    long long len = S[i] - S[i - 1];
    Maxtrix now;
    now.Mc();
    for (int j = 1; j <= 3; ++j) {
      ss[j] += c[j][i];
      if (ss[j]) now.s[j][1] = now.s[j][2] = now.s[j][3] = 0;
    }
    now = fpow(now, len);
    ans = now * ans;
  }
  printf("%d\n", ans.s[2][1]);
}
