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 N = 1e5 + 10, mod = 1e9 + 7;
vector<vector<long long> > mat[8];
vector<pair<long long, long long> > events;
long long ctr[3];
void init();
vector<vector<long long> > solve(vector<vector<long long> > a, int mask,
                                 long long n);
vector<vector<long long> > matrix_exp(vector<vector<long long> > a,
                                      long long e);
vector<vector<long long> > matrix_mul(vector<vector<long long> > a,
                                      vector<vector<long long> > b);
void print(vector<vector<long long> > a) {
  for (auto &r : a) {
    for (auto &c : r) {
      cout << c << ' ';
    }
    cout << endl;
  }
}
int main() {
  init();
  int n;
  long long m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a;
    long long l, r;
    cin >> a >> l >> r;
    events.push_back({l, +a});
    events.push_back({r + 1, -a});
  }
  events.push_back({m + 1, 0});
  sort(events.begin(), events.end());
  long long j = 1;
  vector<vector<long long> > a = {{0, 1, 0}};
  for (auto &p : events) {
    long long i = p.first, c = p.second;
    if (j < i - 1) {
      int k = 0;
      for (int x = 0; x < 3; ++x) {
        if (ctr[x]) {
          k |= (1 << x);
        }
      }
      a = solve(a, k, i - j - 1);
      j = i - 1;
    }
    if (c > 0) {
      ++ctr[c - 1];
    } else {
      --ctr[-c - 1];
    }
  }
  cout << a[0][1];
}
void init() {
  int n = 3, s = (1 << n);
  for (int mask = 0; mask < s; ++mask) {
    mat[mask].resize(n);
    for (int i = 0; i < n; ++i) {
      mat[mask][i].resize(n);
      for (int j = 0; j < n; ++j) {
        if (abs(i - j) <= 1 and !(mask & (1 << j))) {
          mat[mask][i][j] = 1;
        } else {
          mat[mask][i][j] = 0;
        }
      }
    }
  }
}
vector<vector<long long> > solve(vector<vector<long long> > a, int mask,
                                 long long n) {
  vector<vector<long long> > m = matrix_exp(mat[mask], n);
  return matrix_mul(a, m);
}
vector<vector<long long> > matrix_exp(vector<vector<long long> > a,
                                      long long e) {
  vector<vector<long long> > ans = a;
  --e;
  while (e) {
    if (e & 1) {
      ans = matrix_mul(ans, a);
    }
    e >>= 1;
    a = matrix_mul(a, a);
  }
  return ans;
}
vector<vector<long long> > matrix_mul(vector<vector<long long> > a,
                                      vector<vector<long long> > b) {
  int n = a.size(), p = b.size(), m = b[0].size();
  vector<vector<long long> > ans(n);
  for (int i = 0; i < n; ++i) {
    ans[i].resize(m);
    for (int j = 0; j < m; ++j) {
      ans[i][j] = 0;
      for (int k = 0; k < p; ++k) {
        ans[i][j] += a[i][k] * b[k][j];
        ans[i][j] %= mod;
      }
    }
  }
  return ans;
}
