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 = 100100;
const int mod = 1000000007;
const long long INF = (long long)1e18;
int dp[3][3][1 << 3][61], temp[3], c[3], c2[3];
int main() {
  for (int mask = 0; mask < 1 << 3; mask++) {
    for (int i = 0; i < 3; i++) {
      if (mask & (1 << i)) continue;
      for (int j = 0; j < 3; j++) {
        if (mask & (1 << j)) continue;
        dp[i][j][mask][0] = abs(i - j) < 2;
      }
    }
  }
  for (int l = 1; l <= 60; l++) {
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        for (int x = 0; x < 1 << 3; x++) {
          for (int m = 0; m < 3; m++) {
            dp[i][j][x][l] +=
                1LL * dp[i][m][x][l - 1] * dp[m][j][x][l - 1] % mod;
            dp[i][j][x][l] %= mod;
          }
        }
      }
    }
  }
  int n;
  long long m;
  scanf("%d%lld", &n, &m);
  vector<pair<long long, long long> > v[3], vt;
  for (int i = 0; i < n; i++) {
    int l;
    long long a, b;
    scanf("%d%lld%lld", &l, &a, &b);
    v[l - 1].push_back(make_pair(a, b));
  }
  for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());
  for (int i = 0; i < 3; i++) {
    vt.clear();
    int j = 0, k = 0;
    while (j < v[i].size()) {
      long long r = v[i][j].second;
      while (k < v[i].size() && v[i][k].first <= r)
        r = max(r, v[i][k].second), k++;
      vt.push_back(make_pair(v[i][j].first, r + 1));
      j = k;
    }
    v[i] = vt;
  }
  long long ac = m + 1, mask = 0;
  temp[1] = 1;
  int x = 0;
  while (true) {
    int id = 0;
    long long aux = 1;
    for (int i = 0; i < 3; i++) {
      if (v[i].size() == 0) continue;
      if ((1 << i) & mask) {
        if (v[i].back().first > aux)
          id = (1 << i), aux = v[i].back().first;
        else if (v[i].back().first == aux)
          id = id | (1 << i);
      } else {
        if (v[i].back().second > aux)
          id = (1 << i), aux = v[i].back().second;
        else if (v[i].back().second == aux)
          id = id | (1 << i);
      }
    }
    int nmask = mask;
    for (int i = 0; i < 3; i++) {
      if ((1 << i) & id) {
        if ((1 << i) & mask) v[i].pop_back();
        nmask ^= 1 << i;
      }
    }
    long long dif = ac - aux - 1;
    if (x) {
      for (int i = 0; i < 3; i++) temp[i] = c[i], c[i] = c2[i] = 0;
      for (int i = 0; i < 3; i++) {
        if (mask & (1 << i)) continue;
        for (int j = 0; j < 3; j++) {
          if (abs(i - j) >= 2) continue;
          c[i] += temp[j];
          c[i] %= mod;
        }
      }
    } else {
      c[1] = 1;
      x = 1;
    }
    for (int l = 0; l <= 60; l++) {
      if (((1LL << l) & dif) == 0) continue;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          c2[i] += 1LL * c[j] * dp[i][j][mask][l] % mod;
          c2[i] %= mod;
        }
      }
      for (int i = 0; i < 3; i++) c[i] = c2[i], c2[i] = 0;
    }
    if (id == 0) break;
    ac = aux;
    mask = nmask;
  }
  printf("%d\n", c[1]);
  return 0;
}
