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 long long MOD = 1e9 + 7;
inline long long read() {
  long long k = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    k = k * 10 + ch - '0';
    ch = getchar();
  }
  return k * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
long long p[4], n, m;
struct ppap {
  long long x, y, op;
} a[20010];
inline bool cmp(ppap a, ppap b) { return a.y < b.y; }
struct juzhen {
  long long a[4][4];
} ans, z;
inline juzhen cheng(juzhen a, juzhen b) {
  juzhen c;
  memset(c.a, 0, sizeof c.a);
  for (long long i = 1; i < 4; i++)
    for (long long j = 1; j < 4; j++)
      for (long long k = 1; k < 4; k++)
        c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j] % MOD) % MOD;
  return c;
}
inline juzhen mi(juzhen a, long long b) {
  juzhen x = a, y = a;
  b--;
  while (b) {
    if (b & 1) x = cheng(x, y);
    y = cheng(y, y);
    b >>= 1;
  }
  return x;
}
signed main() {
  n = read();
  m = read();
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    long long k = read(), l = read(), r = read();
    if (l == 1 && k == 2) return puts("0") & 0;
    if (l == 1) l++;
    a[++cnt] = (ppap){k, l, 1};
    a[++cnt] = (ppap){k, r, 0};
  }
  a[++cnt] = (ppap){2, 1, 2};
  sort(a + 1, a + cnt + 1, cmp);
  long long b = 0, i = 2;
  ans.a[1][2] = 1;
  a[++cnt] = (ppap){2, m, 2};
  for (; i <= cnt;) {
    if ((b & 2) == 0) {
      memset(z.a, 0, sizeof z.a);
      if (!b) {
        z.a[1][2] = z.a[2][2] = z.a[3][2] = 1;
        z.a[1][1] = z.a[2][1] = z.a[2][3] = z.a[3][3] = 1;
      }
      if (b == 1) {
        z.a[2][2] = z.a[3][2] = 1;
        z.a[2][3] = z.a[3][3] = 1;
      }
      if (b == 4) {
        z.a[1][2] = z.a[2][2] = 1;
        z.a[1][1] = z.a[2][1] = 1;
      }
      if (b != 5 && a[i].y - a[i - 1].y > 0)
        ans = cheng(ans, mi(z, a[i].y - a[i - 1].y));
    }
    if (a[i].y == m) break;
    while (1) {
      if (a[i].op == 1) {
        p[a[i].x]++;
        if ((b & (1 << a[i].x - 1)) == 0) {
          b ^= (1 << a[i].x - 1);
          ans.a[1][a[i].x] = 0;
        }
      }
      if (a[i].op == 0) {
        p[a[i].x]--;
        if (p[a[i].x] == 0 && (b & (1 << a[i].x - 1))) b ^= (1 << a[i].x - 1);
      }
      i++;
      if (a[i].y != a[i - 1].y) break;
    }
  }
  writeln(ans.a[1][2]);
  return 0;
}
