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;
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 100010;
long long N, M, tem[5];
struct jz {
  long long g[4][4];
  friend jz operator*(jz a, jz b) {
    jz c;
    memset(c.g, 0, sizeof(c.g));
    for (long long k = 1; k <= 3; k++) {
      for (long long i = 1; i <= 3; i++) {
        for (long long j = 1; j <= 3; j++) {
          c.g[i][j] = (c.g[i][j] + (a.g[i][k] * b.g[k][j] % MOD)) % MOD;
        }
      }
    }
    return c;
  }
} zy;
struct xl {
  long long g[4];
  friend xl operator*(xl a, jz b) {
    xl c;
    memset(c.g, 0, sizeof(c.g));
    for (long long i = 1; i <= 3; i++) {
      for (long long j = 1; j <= 3; j++) {
        c.g[i] = (c.g[i] + (a.g[j] * b.g[j][i] % MOD)) % MOD;
      }
    }
    return c;
  }
} st;
struct od {
  long long x, type;
  friend bool operator<(od a, od b) { return a.x < b.x; }
} E[MAXN];
xl kuaisu(xl, long long, jz);
void change(long long);
int main() {
  scanf("%lld%lld", &N, &M);
  for (long long i = 1; i <= N * 2; i += 2) {
    scanf("%lld%lld%lld", &E[i].type, &E[i].x, &E[i + 1].x);
    E[i + 1].type = -E[i].type;
    E[i].x--;
  }
  sort(E + 1, E + N * 2 + 1);
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= 3; j++) {
      zy.g[i][j] = 1;
    }
  }
  st.g[2] = 1;
  zy.g[1][3] = 0;
  zy.g[3][1] = 0;
  long long now = 1;
  for (long long i = 1; i <= N * 2; i++) {
    st = kuaisu(st, E[i].x - now, zy);
    change(E[i].type);
    now = E[i].x;
  }
  st = kuaisu(st, M - now, zy);
  printf("%lld\n", st.g[2] % MOD);
  return 0;
}
xl kuaisu(xl a, long long tim, jz n) {
  while (tim) {
    if (tim & 1) {
      a = a * n;
    }
    tim >>= 1;
    n = n * n;
  }
  return a;
}
void change(long long type) {
  if (type > 0) {
    tem[type]++;
    for (long long i = 1; i <= 3; i++) {
      zy.g[i][type] = 0;
    }
  } else {
    type = -type;
    tem[type]--;
    if (tem[type]) return;
    for (long long i = 1; i <= 3; i++) {
      zy.g[i][type] = 1;
    }
    if (type == 1) {
      zy.g[3][type] = 0;
    } else if (type == 3) {
      zy.g[1][type] = 0;
    }
  }
}
