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>
const uint32_t MAX_M = 3;
const uint32_t MOD = 1e9 + 7;
struct Matrix {
  uint64_t m[MAX_M][MAX_M];
  Matrix() {
    for (uint32_t i = 0; i < MAX_M; i++) {
      for (uint32_t j = 0; j < MAX_M; j++) {
        m[i][j] = 0;
      }
    }
  }
  uint64_t *operator[](uint32_t i) { return m[i]; }
  const uint64_t *operator[](uint32_t i) const { return m[i]; }
  friend Matrix operator*(const Matrix &m1, const Matrix &m2) {
    Matrix ans;
    for (uint32_t i = 0; i < MAX_M; i++) {
      for (uint32_t j = 0; j < MAX_M; j++) {
        for (uint32_t k = 0; k < MAX_M; k++) {
          ans[i][j] += m1[i][k] * m2[k][j];
          ans[i][j] %= MOD;
        }
      }
    }
    return ans;
  }
  static Matrix build(uint32_t *obst) {
    Matrix ans;
    for (uint32_t i = 0; i < MAX_M; i++) {
      if (obst[i] > 0) {
        continue;
      }
      for (uint32_t j = 0; j < MAX_M; j++) {
        uint32_t d = i > j ? i - j : j - i;
        if (d <= 1) {
          ans[i][j] = 1;
        }
      }
    }
    return ans;
  }
};
std::ostream &operator<<(std::ostream &s, const Matrix &m) {
  for (uint32_t i = 0; i < MAX_M; i++) {
    for (uint32_t j = 0; j < MAX_M; j++) {
      s << m[i][j] << " ";
    }
    s << "\n";
  }
  return s << "\n";
}
template <class T>
T fast_pow(const T &a, uint64_t b) {
  if (b == 1) {
    return a;
  }
  T ans = fast_pow(a, b / 2);
  ans = ans * ans;
  if (b % 2) {
    ans = ans * a;
  }
  return ans;
}
struct Obst {
  uint64_t x;
  uint32_t y;
  int32_t val;
  Obst(uint64_t pX = 0, uint32_t pY = 0, int32_t pVal = 0)
      : x(pX), y(pY), val(pVal) {}
  friend bool operator<(const Obst &a, const Obst &b) { return a.x < b.x; }
};
std::vector<Obst> obst;
uint64_t width;
void input() {
  uint32_t obstCnt;
  std::cin >> obstCnt >> width;
  for (uint32_t i = 0; i < obstCnt; i++) {
    uint32_t y;
    uint64_t lX, rX;
    std::cin >> y >> lX >> rX;
    obst.push_back(Obst(lX - 1, y - 1, 1));
    obst.push_back(Obst(rX, y - 1, -1));
  }
}
int main() {
  input();
  std::sort(obst.begin(), obst.end());
  uint32_t curCnt[MAX_M];
  for (uint32_t i = 0; i < MAX_M; i++) {
    curCnt[i] = 0;
  }
  Matrix ans;
  ans[1][1] = 1;
  uint64_t lastX = 0;
  for (const Obst &o : obst) {
    uint64_t len = o.x - lastX;
    if (len > 0) {
      Matrix trans = Matrix::build(curCnt);
      ans = ans * fast_pow(trans, len);
    }
    lastX = o.x;
    curCnt[o.y] += o.val;
  }
  if (width - 1 - lastX > 0) {
    Matrix trans = Matrix::build(curCnt);
    ans = ans * fast_pow(trans, width - 1 - lastX);
  }
  std::cout << ans[1][1] << "\n";
}
