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;
const int maxn = 1e4 + 5;
class Matrix {
 public:
  long long a[3][3];
  int n;
  void Init(int key) {
    memset(a, 0, sizeof a);
    if (key)
      for (int i = 0; i < n; i++) a[i][i] = 1;
  }
  Matrix operator*(const Matrix& b) {
    Matrix c;
    c.n = n;
    c.Init(0);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j] % mod) % mod;
    return c;
  }
  Matrix Power(long long t) {
    Matrix ans, p = *this;
    ans.n = p.n;
    ans.Init(1);
    while (t) {
      if (t & 1) ans = ans * p;
      p = p * p;
      t >>= 1;
    }
    return ans;
  }
  void Print() {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j == 0)
          printf("%lld", a[i][j]);
        else
          printf(" %lld", a[i][j]);
      }
      puts("");
    }
  }
};
struct node {
  int x, tag;
  long long y;
  friend bool operator<(const node& a, const node& b) { return a.y < b.y; }
} a[maxn * 2];
long long sum[3], b[3];
void calc(long long n) {
  Matrix f, A;
  f.Init(0);
  A.Init(0);
  f.n = A.n = 3;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (sum[j] == 0)
        f.a[i][j] = 1;
      else
        f.a[i][j] = 0;
    }
  }
  f.a[0][2] = f.a[2][0] = 0;
  A.a[0][0] = b[0], A.a[0][1] = b[1], A.a[0][2] = b[2];
  A = A * f.Power(n);
  b[0] = A.a[0][0], b[1] = A.a[0][1], b[2] = A.a[0][2];
}
int main() {
  int n;
  long long m;
  scanf("%d%lld", &n, &m);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    long long l, r;
    scanf("%d%lld%lld", &x, &l, &r);
    a[++cnt].x = x - 1, a[cnt].y = l - 1, a[cnt].tag = 1;
    a[++cnt].x = x - 1, a[cnt].y = r, a[cnt].tag = -1;
  }
  sort(a + 1, a + cnt + 1);
  b[0] = b[2] = 0, b[1] = 1;
  long long cur = 1;
  for (int i = 1; i <= cnt; i++) {
    calc(a[i].y - cur);
    cur = a[i].y;
    sum[a[i].x] += a[i].tag;
  }
  calc(m - cur);
  printf("%lld\n", b[1]);
  return 0;
}
