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 md = 1000000007;
struct matrix {
  long long a[3][3], n, m;
  void print() {
    for (long long i = 0; i < n; ++i) {
      for (long long j = 0; j < m; ++j) {
        cout << a[i][j] << " ";
      }
      cout << endl;
    }
  }
};
matrix operator*(matrix &a, matrix &b) {
  matrix c;
  c.n = a.n;
  c.m = a.m;
  for (long long i = 0; i < c.n; ++i) {
    for (long long j = 0; j < c.m; ++j) {
      c.a[i][j] = 0;
    }
  }
  for (long long i = 0; i < c.n; ++i) {
    for (long long j = 0; j < c.m; ++j) {
      for (long long k = 0; k < a.m; ++k) {
        c.a[i][j] += (a.a[i][k] * b.a[k][j]) % md;
        c.a[i][j] %= md;
      }
    }
  }
  return c;
}
matrix bin_pow(matrix a, long long n) {
  matrix res;
  res.n = 3;
  res.m = 3;
  for (long long i = 0; i < 3; ++i) {
    for (long long j = 0; j < 3; ++j) {
      res.a[i][j] = 0;
    }
  }
  res.a[0][0] = 1;
  res.a[1][1] = 1;
  res.a[2][2] = 1;
  while (n > 0) {
    if (n % 2 == 0) {
      n >>= 1;
      a = a * a;
    } else {
      n--;
      res = res * a;
    }
  }
  return res;
}
long long n, m, z, l, r, t, us1[3], us2[3];
matrix ans, x, y;
pair<long long, pair<long long, long long> > a[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    cin >> z >> l >> r;
    z--;
    a[++t] = make_pair(l, make_pair(z, 1));
    a[++t] = make_pair(r + 1, make_pair(z, -1));
  }
  sort(a + 1, a + t + 1);
  l = 1;
  ans.n = 1;
  ans.m = 3;
  ans.a[0][0] = 0;
  ans.a[0][1] = 1;
  ans.a[0][2] = 0;
  x.n = 3;
  x.m = 3;
  a[0].first = 1;
  a[t + 1].first = m + 1;
  for (long long e = 1; e <= t + 1; ++e) {
    us2[a[e].second.first] += a[e].second.second;
    if (e > 0 && a[e].first != a[e - 1].first) {
      r = a[e].first;
      for (long long i = 0; i < 3; ++i) {
        for (long long j = 0; j < 3; ++j) {
          if (abs(i - j) <= 1 && us1[i] == 0 && us1[j] == 0)
            x.a[i][j] = 1;
          else
            x.a[i][j] = 0;
        }
      }
      if (r - 1 - l >= 0) x = bin_pow(x, r - 1 - l);
      if (r - 1 - l >= 0) ans = ans * x;
      l = r;
    }
    if (e <= t && a[e + 1].first != a[e].first) {
      for (long long i = 0; i < 3; ++i) {
        for (long long j = 0; j < 3; ++j) {
          if (abs(i - j) <= 1 && us1[i] == 0 && us2[j] == 0)
            x.a[i][j] = 1;
          else
            x.a[i][j] = 0;
        }
      }
      ans = ans * x;
      for (long long i = 0; i < 3; ++i) {
        us1[i] = us2[i];
      }
    }
  }
  cout << ans.a[0][1];
}
