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;
inline long long read() {
  register long long x = 0, t = 1;
  register char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return x * t;
}
struct Maxtrix {
  long long s[5][5];
  void clear() { memset(s, 0, sizeof(s)); }
  void init() {
    clear();
    s[1][1] = s[2][2] = s[3][3] = 1;
  }
  void M000() {
    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*(Maxtrix a, Maxtrix b) {
  Maxtrix ret;
  ret.clear();
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j)
      for (int k = 1; k <= 3; ++k)
        ret.s[i][j] = (ret.s[i][j] + 1ll * a.s[i][k] * b.s[k][j] % 1000000007) %
                      1000000007;
  return ret;
}
Maxtrix fpow(Maxtrix a, long long b) {
  Maxtrix s;
  s.init();
  while (b) {
    if (b & 1) s = s * a;
    a = a * a;
    b >>= 1ll;
  }
  return s;
}
struct Block {
  long long l, r;
  int a;
} blk[11111];
long long tot, top;
long long S[11111 << 2];
long long c[4][11111 << 1];
long long n, Q;
long long M;
int main() {
  n = read();
  M = read();
  for (int i = 1; i <= n; ++i) {
    int a = read();
    long long l = read(), r = read();
    S[++top] = l - 1, S[++top] = r;
    blk[++tot] = (Block){l, r, 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) {
    long long L = lower_bound(&S[1], &S[top + 1], blk[i].l) - S;
    long long R = lower_bound(&S[1], &S[top + 1], blk[i].r) - S;
    c[blk[i].a][L]++;
    c[blk[i].a][R + 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.M000();
    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;
  }
  cout << ans.s[2][1] << endl;
  return 0;
}
