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
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;

public class x954F
{
    static final long MOD = 1000000007L;
    static long[][] coefficients = {{1, 1, 0},{1, 1, 1}, {0, 1, 1}};
    public static void main(String hi[]) throws Exception
    {
        BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(infile.readLine());
        int N = Integer.parseInt(st.nextToken());
        long M = Long.parseLong(st.nextToken());
        Point[] arr = new Point[N<<1];
        for(int i=0; i < N; i++)
        {
            st = new StringTokenizer(infile.readLine());
            int b = Integer.parseInt(st.nextToken())-1;
            long L = Long.parseLong(st.nextToken());
            long R = Long.parseLong(st.nextToken());
            arr[i*2] = new Point(L, b, true);
            arr[i*2+1] = new Point(R+1, b, false);
        }
        Arrays.sort(arr, (x,y) -> {
            int temp = Long.compare(x.pos, y.pos);
            if(temp != 0)
                return temp;
            if(x.start != y.start)
                return x.start ? 1 : -1;
            return x.b-y.b;
        });
        //at col=1
        long[][] res = {{0}, {1L}, {0}};
        long[][] mat;
        long prevcol = 1L;
        int[] mask = new int[3];
        int dex = 0;
        while(dex < N<<1)
        {
            mat = copy(coefficients);
            for(int b=0; b < 3; b++)
                if(mask[b] > 0)
                    for(int c=0; c < 3; c++)
                        mat[b][c] = 0;
            long pos = arr[dex].pos;
            long pow = pos-prevcol;
            if(prevcol == 1)    pow--;
            res = multiply(power(mat, pow), res);
            while(dex < N<<1 && arr[dex].pos == pos)
            {
                if(arr[dex].start)
                    mask[arr[dex].b]++;
                else
                    mask[arr[dex].b]--;
                dex++;
            }
            prevcol = pos;
        }
        mat = copy(coefficients);
        if(debug)print(res);
        res = multiply(power(mat, M-prevcol+1), res);
        if(debug)print(res);
        System.out.println(res[1][0]);
    }
    static boolean debug = false;
    public static void print(long[][] grid)
    {
        for(int r=0; r < 3; r++)
        {
            for(long x: grid[r])
                System.out.print(x+" ");
            System.out.println();
        }
    }
    public static long[][] copy(long[][] grid)
    {
        int N = grid.length; int M = grid[0].length;
        long[][] res = new long[N][M];
        for(int r=0; r < N; r++)
            for(int c=0; c < M; c++)
                res[r][c] = grid[r][c];
        return res;
    }
    public static long[][] multiply(long[][] left, long[][] right)
    {
        int N = left.length;
        int M = right[0].length;
        long[][] res = new long[N][M];
        for(int a=0; a < N; a++)
            for(int b=0; b < M; b++)
                for(int c=0; c < left[0].length; c++)
                {
                    res[a][b] += (left[a][c]*right[c][b])%MOD;
                    if(res[a][b] >= MOD)
                        res[a][b] -= MOD;
                }
        return res;
    }
    public static long[][] power(long[][] grid, long pow)
    {
        long[][] res = new long[grid.length][grid[0].length];
        for(int i=0; i < res.length; i++)
            res[i][i] = 1L;
        long[][] curr = grid.clone();
        while(pow > 0)
        {
            if((pow&1L) == 1L)
                res = multiply(curr, res);
            pow >>= 1;
            curr = multiply(curr, curr);
        }
        return res;
    }
}
class Point
{
    public long pos;
    public int b;
    public boolean start;

    public Point(long x, int bb, boolean xx)
    {
        pos = x;
        b = bb;
        start = xx;
    }
}