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 = 1e4 + 4;
const long long mod = 1e9 + 7;
struct Mat {
  static const long long M = 3;
  long long v[M][M];
  Mat() { memset(v, 0, sizeof v); }
  void eye() {
    for (int i = 0; i < M; i++) v[i][i] = 1;
  }
  long long* operator[](long long x) { return v[x]; }
  const long long* operator[](long long x) const { return v[x]; }
  Mat operator*(const Mat& B) {
    const Mat& A = *this;
    Mat ret;
    for (int k = 0; k < M; k++)
      for (int i = 0; i < M; i++)
        if (A[i][k])
          for (int j = 0; j < M; j++)
            ret[i][j] = (ret[i][j] + A[i][k] * B[k][j] % mod) % mod;
    return ret;
  }
  Mat pow(long long n) const {
    Mat A = *this, ret;
    ret.eye();
    for (; n; n >>= 1, A = A * A)
      if (n & 1) ret = ret * A;
    return ret;
  }
  Mat operator+(const Mat& B) {
    const Mat& A = *this;
    Mat ret;
    for (int i = 0; i < M; i++)
      for (int j = 0; j < M; j++) ret[i][j] = (A[i][j] + B[i][j]) % mod;
    return ret;
  }
  void prt() const {
    for (int i = 0; i < M; i++)
      for (int j = 0; j < M; j++)
        printf("%lld%c", (*this)[i][j], j == M - 1 ? '\n' : ' ');
  }
};
int n;
long long m;
vector<pair<long long, long long> > v[4];
vector<pair<long long, pair<long long, long long> > > pos;
Mat ori;
int main() {
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) ori[i][j] = 1;
  ori[0][2] = ori[2][0] = 0;
  scanf("%d%lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    int p;
    long long l, r;
    scanf("%d%lld%lld", &p, &l, &r);
    v[p].push_back(make_pair(l, r));
  }
  for (int k = 1; k <= 3; k++)
    if (v[k].size()) {
      sort(v[k].begin(), v[k].end());
      long long l = v[k][0].first, r = v[k][0].second;
      for (int i = 1; i < v[k].size(); i++) {
        if (v[k][i].first <= r)
          r = max(r, v[k][i].second);
        else {
          pos.push_back(make_pair(l, make_pair(k, 0)));
          pos.push_back(make_pair(r + 1, make_pair(k, 1)));
          l = v[k][i].first;
          r = v[k][i].second;
        }
      }
      pos.push_back(make_pair(l, make_pair(k, 0)));
      pos.push_back(make_pair(r + 1, make_pair(k, 1)));
    }
  pos.push_back(make_pair(m + 1, make_pair(1, 0)));
  sort(pos.begin(), pos.end());
  int f = 0;
  long long p = 1;
  Mat ans;
  ans[1][0] = 1;
  Mat now;
  now.eye();
  for (auto t : pos) {
    Mat tmp;
    tmp = ori;
    for (int i = 0; i < 3; i++)
      if ((1 << i) & f) {
        for (int j = 0; j < 3; j++) tmp[i][j] = 0;
      }
    now = tmp.pow(t.first - 1 - p) * now;
    p = t.first - 1;
    f ^= (1 << (t.second.first - 1));
  }
  ans = now * ans;
  printf("%lld\n", ans[1][0]);
  return 0;
}
