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 java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemFRunnersProblem solver = new ProblemFRunnersProblem();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemFRunnersProblem {
        private long[][] copy(long[][] mat) {
            long[][] ans = new long[3][3];
            for (int i = 0; i < 3; ++i) {
                ans[i] = Arrays.copyOf(mat[i], 3);
            }
            return ans;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            final int mod = (int) 1e9 + 7;
            int n = in.nextInt();
            long m = in.nextLong();
            ArrayList<Event> q = new ArrayList<>();
            for (int i = 0; i < n; ++i) {
                int a = in.nextInt() - 1;
                long l = in.nextLong();
                long r = in.nextLong();
                q.add(new Event(true, a, l));
                q.add(new Event(false, a, r + 1));
            }
            Collections.sort(q);
            int[] blocked = new int[3];
            long col = 1;
            long[][] init = {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}};
            long[][] A = {{0, 1, 0}};
            long[][] curmat = copy(init);
            for (Event e : q) {
                long diff = e.col - col;
                long[][] mat = matrix.expo(curmat, diff, mod);
                A = matrix.mult(A, mat, mod);
                col = e.col;
                if (e.block) {
                    for (int i = 0; i < 3; ++i) {
                        curmat[e.row][i] = 0;
                    }
                    blocked[e.row]++;
                } else {
                    blocked[e.row]--;
                    if (blocked[e.row] != 0) continue;
                    curmat[e.row] = Arrays.copyOf(init[e.row], 3);
                }
            }
            long diff = m - col;
            long[][] mat = matrix.expo(init, diff, mod);
            A = matrix.mult(A, mat, mod);
            out.println(A[0][1]);
        }

        class Event implements Comparable<Event> {
            boolean block;
            int row;
            long col;

            Event(boolean b, int r, long c) {
                block = b;
                row = r;
                col = c;
            }

            public int compareTo(Event e) {
                return Long.compare(col, e.col);
            }

            public String toString() {
                return String.format("(%d, %d) %s", row, col, block ? "BLOCK" : "UNBLOCK");
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

    static class matrix {
        public static long[][] mult(long[][] mat1, long[][] mat2, int mod) {
            long[][] res = new long[mat1.length][mat2[0].length];
            for (int i = 0; i < res.length; ++i) {
                for (int j = 0; j < res[i].length; ++j) {
                    for (int k = 0; k < mat2.length; ++k) {
                        res[i][j] += mat1[i][k] * mat2[k][j];
                        res[i][j] %= mod;
                    }
                }
            }
            return res;
        }

        public static long[][] copy(long[][] mat) {
            long[][] ans = new long[mat.length][mat[0].length];
            for (int i = 0; i < mat.length; ++i) {
                ans[i] = Arrays.copyOf(mat[i], mat[i].length);
            }
            return ans;
        }

        public static long[][] expo(long[][] mat, long expo, int mod) {
            long[][] P = copy(mat);
            long[][] ans = identity(mat.length);
            while (expo > 0) {
                if (expo % 2 == 0) {
                    P = mult(P, P, mod);
                    expo /= 2;
                } else {
                    ans = mult(P, ans, mod);
                    expo--;
                }
            }
            return ans;
        }

        public static long[][] identity(int size) {
            long[][] mat = new long[size][size];
            for (int i = 0; i < size; ++i)
                mat[i][i] = 1;
            return mat;
        }

    }
}

