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 P = 1000000007;
vector<pair<long long, int>> impediments;
struct matrix {
  long long a[3][3];
  matrix() {}
  matrix(const vector<int>& v) {
    for (int w = 0; w < 9; w++) {
      a[w / 3][w % 3] = (w < v.size()) ? v[w] : 0;
    }
  }
  matrix& operator=(const matrix& m) {
    for (int e = 0; e < 3; e++) {
      for (int r = 0; r < 3; r++) {
        a[e][r] = m.a[e][r];
      }
    }
    return *this;
  }
  matrix& operator*=(const matrix& m) {
    long long temp[3][3];
    for (int e = 0; e < 3; e++) {
      for (int r = 0; r < 3; r++) {
        temp[e][r] = 0;
        for (int w = 0; w < 3; w++) {
          temp[e][r] += a[e][w] * m.a[w][r];
        }
        temp[e][r] %= P;
      }
    }
    for (int e = 0; e < 3; e++) {
      for (int r = 0; r < 3; r++) {
        a[e][r] = temp[e][r];
      }
    }
    return *this;
  }
};
struct vect_3 {
  vect_3(const vector<long long>& v) {
    for (int w = 0; w < 3; w++) {
      a[w] = (w < v.size()) ? v[w] : 0;
    }
  }
  vect_3& operator*=(const matrix& m) {
    long long temp[] = {0, 0, 0};
    for (int w = 0; w < 3; w++) {
      for (int e = 0; e < 3; e++) {
        temp[e] += a[w] * m.a[w][e];
      }
    }
    for (int w = 0; w < 3; w++) {
      a[w] = temp[w] % P;
    }
    return *this;
  }
  long long a[3];
};
matrix powers[8][63];
void powers_init() {
  for (int w = 0; w < 8; w++) {
    matrix m({1, 1, 0, 1, 1, 1, 0, 1, 1});
    for (int e = 0; e < 3; e++) {
      if ((w & (1 << e)) > 0) {
        m.a[0][e] = m.a[1][e] = m.a[2][e] = 0;
      }
    }
    powers[w][0] = {{1, 0, 0, 0, 1, 0, 0, 0, 1}};
    for (int e = 1; e < 63; e++) {
      powers[w][e] = m;
      m *= m;
    }
  }
}
void power_and_mult(vect_3& res, int mask, long long p) {
  int no = 1;
  while (p > 0) {
    if (p % 2 == 1) {
      res *= powers[mask][no];
    }
    p /= 2;
    no++;
  }
}
int main() {
  powers_init();
  int num_imp;
  long long ncol;
  cin >> num_imp >> ncol;
  for (int w = 0; w < num_imp; w++) {
    int row;
    long long start, finish;
    cin >> row >> start >> finish;
    row--;
    impediments.push_back({start, row * 2});
    impediments.push_back({finish + 1, row * 2 + 1});
  }
  impediments.push_back({ncol, 0});
  sort(impediments.begin(), impediments.end());
  long long prev_point = 2;
  int blocked[] = {0, 0, 0};
  vect_3 res({0, 1, 0});
  int prev_mask = 0;
  int pos = 0;
  while (pos < impediments.size()) {
    long long delta = impediments[pos].first - prev_point;
    power_and_mult(res, prev_mask, delta);
    prev_point = impediments[pos].first;
    while ((pos < impediments.size()) &&
           (impediments[pos].first == prev_point)) {
      blocked[impediments[pos].second / 2] +=
          (impediments[pos].second % 2 == 0) ? 1 : -1;
      pos++;
    }
    prev_mask = 0;
    for (int w = 0; w < 3; w++) {
      if (blocked[w]) {
        prev_mask += 1 << w;
      }
    }
  }
  cout << (res.a[0] + res.a[1] + res.a[2]) % P << "\n";
  return 0;
}
