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 maxn = 5;
const long long mod = 1e9 + 7;
struct Matrix {
  long long maze[maxn][maxn];
  int len;
  Matrix() {
    memset(maze, 0, sizeof(maze));
    len = 3;
  }
  Matrix(int lens) : len(lens) { memset(maze, 0, sizeof(maze)); }
  void einit() {
    for (int i = 0; i < len; i++)
      for (int j = 0; j < len; j++) maze[i][j] = (i == j);
  }
  void Creat(int lens) {
    len = lens;
    if (len > maxn) exit(1);
    for (int i = 0; i < len; i++)
      for (int j = 0; j < len; j++) scanf("%lld", &maze[i][j]);
  }
  void output() {
    for (int i = 0; i < len; i++) {
      for (int j = 0; j < len - 1; j++) printf("%lld ", maze[i][j]);
      printf("%lld\n", maze[i][len - 1]);
    }
  }
  Matrix operator*(const Matrix &a) {
    Matrix ans(len);
    for (int k = 0; k < len; k++) {
      for (int i = 0; i < len; i++)
        if (maze[i][k]) {
          long long temp;
          for (int j = 0; j < len; j++)
            if (a.maze[k][j]) {
              temp = (maze[i][k] * a.maze[k][j]) % mod;
              ans.maze[i][j] = (ans.maze[i][j] + temp) % mod;
            }
        }
    }
    return ans;
  }
  Matrix operator^(const long long &b) const {
    Matrix ans(len), a = (*this);
    ans.einit();
    long long t = b;
    while (t) {
      if (t & 1) ans = ans * a;
      a = a * a;
      t >>= 1;
    }
    return ans;
  }
  void operator=(const Matrix &a) {
    len = a.len;
    for (int i = 0; i < len; i++)
      for (int j = 0; j < len; j++) maze[i][j] = a.maze[i][j];
  }
};
Matrix A(3), M[8];
struct node {
  long long l;
  int x, p;
  bool operator<(const node &b) const { return l < b.l; }
};
vector<node> store;
int cnt[3];
int n;
long long m;
int cal() {
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    ans |= ((cnt[i] == 0) << i);
  }
  return ans;
}
int main() {
  for (int i = 0; i < 8; i++) {
    if ((i & 1)) M[i].maze[0][0] = M[i].maze[0][1] = 1;
    if ((i & 2)) M[i].maze[1][0] = M[i].maze[1][1] = M[i].maze[1][2] = 1;
    if ((i & 4)) M[i].maze[2][1] = M[i].maze[2][2] = 1;
  }
  while (~scanf("%d%I64d", &n, &m)) {
    int x;
    long long l, r;
    store.clear();
    A.maze[0][1] = 1;
    for (int i = 0; i < n; i++) {
      scanf("%d%I64d%I64d", &x, &l, &r);
      store.push_back((node){l, x - 1, 1});
      store.push_back((node){r + 1, x - 1, -1});
    }
    sort(store.begin(), store.end());
    long long las = 1;
    cnt[0] = cnt[1] = cnt[2] = 0;
    for (int i = 0; i < (int)store.size(); i++) {
      long long now = store[i].l;
      if (now > las) {
        A = A * (M[cal()] ^ (now - las));
      }
      cnt[store[i].x] += store[i].p;
      las = now;
    }
    A = A * (M[7] ^ (m - las));
    printf("%I64d\n", A.maze[0][1]);
  }
  return 0;
}
