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 MAXN = 1e18;
const long long LOG = 61;
const long long MOD = 1e9 + 7;
long long n, m;
vector<vector<long long>> mult(vector<vector<long long>> &a,
                               vector<vector<long long>> &b) {
  vector<vector<long long>> ans(3, vector<long long>(3, 0));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % MOD;
      }
    }
  }
  return ans;
}
vector<long long> mult(vector<vector<long long>> &a, vector<long long> &b) {
  vector<long long> ans(3, 0);
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      ans[i] = (ans[i] + a[i][j] * b[j]) % MOD;
    }
  }
  return ans;
}
vector<vector<long long>> preM[LOG];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  vector<vector<long long>> M{{1, 1, 0}, {1, 1, 1}, {0, 1, 1}};
  vector<vector<long long>> ev;
  for (int i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ev.push_back({b - 1, 1, a - 1});
    ev.push_back({c, -1, a - 1});
  }
  ev.push_back({m, 0, 1});
  sort(ev.begin(), ev.end());
  vector<long long> bl{0, 0, 0};
  vector<long long> st{0, 1, 0};
  vector<vector<long long>> curM = M;
  long long pos = 1;
  for (auto e : ev) {
    long long np = e[0], a = e[2], d = e[1];
    if (np > pos) {
      long long diff = np - pos;
      long long p = 1LL;
      while (diff) {
        if (diff & p) {
          diff -= p;
          st = mult(curM, st);
        }
        p <<= 1LL;
        curM = mult(curM, curM);
      }
      pos = np;
    }
    bl[a] += d;
    curM = M;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (bl[i]) curM[i][j] = 0;
      }
    }
  }
  cout << st[1] << endl;
}
