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 mod = 1000000007;
long long add(long long a, long long b) {
  long long res = a + b;
  return res >= mod ? res - mod : res;
}
long long mul(long long a, long long b) { return a * b % mod; }
vector<vector<long long>> matmul(const vector<vector<long long>>& a,
                                 const vector<vector<long long>>& b) {
  int n = ((int)(a).size()), m = ((int)(b).size()), o = ((int)(b[0]).size());
  vector<vector<long long>> ans(n, vector<long long>(o));
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (o); j++)
      for (int k = (0); k < (m); k++)
        ans[i][j] = add(ans[i][j], mul(a[i][k], b[k][j]));
  return ans;
}
vector<vector<long long>> powmod(vector<vector<long long>> a, long long b) {
  assert(b >= 0);
  int n = ((int)(a).size());
  vector<vector<long long>> ans(n, vector<long long>(n));
  for (int i = (0); i < (n); i++) ans[i][i] = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = matmul(ans, a);
    a = matmul(a, a);
  }
  return ans;
}
vector<pair<long long, pair<int, int>>> event;
int cnt[4];
int n;
long long m;
int main() {
  scanf("%d%lld", &n, &m);
  for (int i = (0); i < (n); i++) {
    long long l, r;
    int a;
    scanf("%d%lld%lld", &a, &l, &r);
    a--;
    l--;
    event.push_back(make_pair(l, make_pair(0, a)));
    event.push_back(make_pair(r, make_pair(1, a)));
  }
  event.push_back(make_pair(1, make_pair(0, 3)));
  event.push_back(make_pair(m, make_pair(1, 3)));
  sort((event).begin(), (event).end());
  vector<vector<long long>> cur = {{0}, {1}, {0}};
  for (int i = 0; i < (((int)(event).size()) - 1); i++) {
    int t = event[i].second.first, of = event[i].second.second;
    if (t == 0)
      cnt[of]++;
    else
      cnt[of]--;
    vector<vector<long long>> now(3, vector<long long>(3));
    if (cnt[0] == 0) now[0] = {1, 1, 0};
    if (cnt[1] == 0) now[1] = {1, 1, 1};
    if (cnt[2] == 0) now[2] = {0, 1, 1};
    long long len = event[i + 1].first - event[i].first;
    cur = matmul(powmod(now, len), cur);
  }
  printf("%lld", cur[1][0]);
}
