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>
struct matrix {
  int a[3][3], r, c;
  inline matrix() { memset(a, 0, sizeof a); }
  matrix operator*(const matrix& b) {
    matrix c;
    c.r = r;
    c.c = b.c;
    for (int i = 0; i < r; ++i)
      for (int k = 0; k < b.c; ++k)
        if (a[i][k])
          for (int j = 0; j < b.r; ++j)
            c.a[i][j] =
                (c.a[i][j] + a[i][k] * (long long)b.a[k][j]) % 1000000007;
    return c;
  }
} a, I, Y[10];
matrix pow(matrix a, long long b) {
  matrix ret;
  ret.r = ret.c = 3;
  ret.a[0][0] = ret.a[1][1] = ret.a[2][2] = 1;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) ret = ret * a;
  return ret;
}
int n;
long long m;
std::vector<long long> wz;
struct sgt {
  struct nd {
    int ls, rs, sz;
  } d[5000005];
  int nod, rt;
  void add(int& o, long long l, long long r, const long long& pos,
           const long long& x) {
    if (!o) o = ++nod;
    d[o].sz += x;
    if (l == r) return;
    const long long mid = l + r >> 1;
    if (pos <= mid)
      add(d[o].ls, l, mid, pos, x);
    else
      add(d[o].rs, mid + 1, r, pos, x);
  }
  int query(int o, long long l, long long r, const long long& L,
            const long long& R) {
    if (!o) return 0;
    if (L <= l && r <= R) return d[o].sz;
    const long long mid = l + r >> 1;
    if (L <= mid && mid < R)
      return query(d[o].ls, l, mid, L, R) + query(d[o].rs, mid + 1, r, L, R);
    if (L <= mid) return query(d[o].ls, l, mid, L, R);
    return query(d[o].rs, mid + 1, r, L, R);
  }
} s[3];
void init() {
  *Y = I;
  for (int i = 1; i < 8; ++i) {
    Y[i] = I;
    for (int j = 0; j < 3; ++j)
      if (i >> j & 1) Y[i].a[0][j] = Y[i].a[1][j] = Y[i].a[2][j] = 0;
  }
}
int main() {
  I.r = I.c = 3;
  I.a[0][0] = I.a[0][1] = I.a[1][0] = I.a[1][1] = I.a[1][2] = I.a[2][1] =
      I.a[2][2] = 1;
  a.r = 1, a.c = 3;
  a.a[0][1] = 1;
  init();
  scanf("%d%lld", &n, &m);
  wz.push_back(2), wz.push_back(m + 1);
  while (n--) {
    int x;
    long long l, r;
    scanf("%d%lld%lld", &x, &l, &r);
    --x;
    wz.push_back(l), wz.push_back(r + 1);
    s[x].add(s[x].rt, 1, m, l, 1);
    s[x].add(s[x].rt, 1, m, r + 1, -1);
  }
  std::sort(wz.begin(), wz.end());
  wz.erase(std::unique(wz.begin(), wz.end()), wz.end());
  for (int i = 0; i < wz.size() - 1; ++i) {
    int zt = 0;
    for (int j = 0; j < 3; ++j)
      if (s[j].query(s[j].rt, 1, m, 1, wz[i + 1] - 1)) zt |= 1 << j;
    a = a * pow(Y[zt], wz[i + 1] - wz[i]);
  }
  printf("%d\n", a.a[0][1]);
  return 0;
}
