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;
set<long long> s;
map<long long, int> mp;
long long n, m;
long long a[20005], l[20005], r[20005], len[20005], save[20005];
long long blocked[3][20005];
vector<vector<long long> > mul(vector<vector<long long> > A,
                               vector<vector<long long> > B) {
  vector<vector<long long> > C(A.size(), vector<long long>(B[0].size()));
  for (long long i = 0; i < A.size(); i++)
    for (long long k = 0; k < B.size(); k++)
      for (long long j = 0; j < B[0].size(); j++)
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % 1000000007;
  return C;
}
vector<vector<long long> > _pow(vector<vector<long long> > A, long long n) {
  vector<vector<long long> > B(A.size(), vector<long long>(A.size()));
  for (long long i = 0; i < A.size(); i++) B[i][i] = 1LL;
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
int main() {
  vector<vector<long long> > A1(3, vector<long long>(3)),
      A2(3, vector<long long>(3)), A3(3, vector<long long>(3)),
      A4(3, vector<long long>(3)), A5(3, vector<long long>(3)),
      A6(3, vector<long long>(3)), A7(3, vector<long long>(3)),
      A8(3, vector<long long>(3));
  A1[0][0] = A1[0][1] = A1[1][0] = A1[1][1] = A1[1][2] = A1[2][2] = A1[2][1] =
      1;
  A1[0][2] = A1[2][0] = 0;
  A2 = A3 = A4 = A5 = A6 = A7 = A8 = A1;
  for (long long i = 0; i < 3; i++)
    A2[0][i] = A4[0][i] = A6[0][i] = A8[0][i] = 0;
  for (long long i = 0; i < 3; i++)
    A3[1][i] = A4[1][i] = A7[1][i] = A8[1][i] = 0;
  for (long long i = 0; i < 3; i++)
    A5[2][i] = A6[2][i] = A7[2][i] = A8[2][i] = 0;
  scanf("%I64d%I64d", &n, &m);
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d%I64d%I64d", &a[i], &l[i], &r[i]);
    r[i]++;
    s.insert(l[i]);
    s.insert(r[i]);
  }
  long long t = 0;
  for (auto it = s.begin(); it != s.end(); it++) {
    save[++t] = *it;
    mp[save[t]] = t;
  }
  for (long long i = 1; i <= n; i++) {
    l[i] = mp[l[i]];
    r[i] = mp[r[i]];
  }
  memset(blocked, 0, sizeof(blocked));
  for (long long i = 1; i <= n; i++) {
    blocked[a[i] - 1][l[i]]++;
    blocked[a[i] - 1][r[i]]--;
  }
  for (long long i = 0; i < 3; i++) {
    for (long long j = 1; j <= t; j++) {
      blocked[i][j] += blocked[i][j - 1];
    }
  }
  vector<vector<long long> > x(3, vector<long long>(1));
  x[0][0] = 0;
  x[1][0] = 1;
  x[2][0] = 0;
  x = mul(_pow(A1, save[1] - 2), x);
  for (long long i = 1; i < t; i++) {
    long long num = 0;
    if (blocked[2][i]) num += 4;
    if (blocked[1][i]) num += 2;
    if (blocked[0][i]) num += 1;
    num++;
    long long len = (save[i + 1] - save[i]) % (1000000007 - 1);
    if (num == 1) x = mul(_pow(A1, len), x);
    if (num == 2) x = mul(_pow(A2, len), x);
    if (num == 3) x = mul(_pow(A3, len), x);
    if (num == 4) x = mul(_pow(A4, len), x);
    if (num == 5) x = mul(_pow(A5, len), x);
    if (num == 6) x = mul(_pow(A6, len), x);
    if (num == 7) x = mul(_pow(A7, len), x);
    if (num == 8) x = mul(_pow(A8, len), x);
  }
  x = mul(_pow(A1, m - save[t] + 1), x);
  printf("%I64d\n", x[1][0]);
  return 0;
}
