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 INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e4 + 7;
struct Mat {
  vector<vector<long long> > a;
  Mat() {}
  Mat(int n, int m) { a.resize(n, vector<long long>(m)); }
  Mat operator*(const Mat &b) const {
    int n = (int)(a).size(), m = (int)(b.a[0]).size(), nm = (int)(b.a).size();
    Mat r(n, m);
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (m); ++j) {
        for (int k = (0); k < (nm); ++k) r.a[i][j] += a[i][k] * b.a[k][j];
        r.a[i][j] %= MOD;
      }
    return r;
  }
  Mat operator^(long long b) {
    int n = (int)(a).size();
    Mat r(n, n), t = *this;
    for (int i = (0); i < ((int)(r.a).size()); ++i) r.a[i][i] = 1;
    for (; b; b >>= 1) {
      if (b & 1) r = r * t;
      t = t * t;
    }
    return r;
  }
  void out() {
    for (int j = (0); j < ((int)(a).size()); ++j) {
      vector<long long> r = a[j];
      for (int i = (0); i < ((int)(r).size()); ++i)
        printf("%lld%c", r[i], " \n"[i == (int)(r).size() - 1]);
    }
  }
};
struct Node {
  long long a, l, r, dl, dr;
} a[N];
long long n, m;
vector<long long> dis;
int cnt[3][N << 1], row[3];
void Init() {
  memset(cnt, 0, sizeof(cnt));
  dis.clear();
  for (int i = (0); i < (n); ++i) {
    scanf("%lld%lld%lld", &a[i].a, &a[i].l, &a[i].r);
    dis.push_back(a[i].l - 1);
    dis.push_back(a[i].r);
  }
  dis.push_back(1);
  dis.push_back(m);
  sort((dis).begin(), (dis).end());
  dis.erase(unique((dis).begin(), (dis).end()), dis.end());
  for (int i = (0); i < (n); ++i) {
    a[i].dl = lower_bound((dis).begin(), (dis).end(), a[i].l) - dis.begin() + 1;
    a[i].dr = lower_bound((dis).begin(), (dis).end(), a[i].r) - dis.begin() + 1;
  }
  for (int i = (0); i < (n); ++i) {
    cnt[a[i].a - 1][a[i].dl]++;
    cnt[a[i].a - 1][a[i].dr + 1]--;
  }
}
int Solve() {
  Mat ans(3, 1);
  ans.a[0][0] = ans.a[2][0] = 0;
  ans.a[1][0] = 1;
  for (int i = (0); i < (3); ++i) row[i] = 0;
  for (int i = (1); i < ((int)(dis).size()); ++i) {
    int di = i + 1;
    long long len = dis[i] - dis[i - 1];
    Mat tmp(3, 3);
    tmp.a[0][0] = tmp.a[0][1] = 1;
    tmp.a[0][2] = 0;
    tmp.a[1][0] = tmp.a[1][1] = tmp.a[1][2] = 1;
    tmp.a[2][0] = 0;
    tmp.a[2][1] = tmp.a[2][2] = 1;
    for (int j = (0); j < (3); ++j) {
      row[j] += cnt[j][di];
      if (row[j])
        for (int k = (0); k < (3); ++k) tmp.a[j][k] = 0;
    }
    ans = (tmp ^ len) * ans;
  }
  return printf("%lld\n", ans.a[1][0]);
}
int main() {
  while (~scanf("%lld%lld", &n, &m)) {
    Init();
    Solve();
  }
  return 0;
}
