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.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
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;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            long m = in.nextLong();

            long[][] data = new long[n * 2 + 1][3];
            for (int s = 0; s < n; s++) {
                int f = in.nextInt() - 1;
                long from = in.nextLong() - 1;
                long to = in.nextLong() - 1;
                data[s * 2][0] = f;
                data[s * 2][1] = from;
                data[s * 2][2] = 1;
                data[s * 2 + 1][0] = f;
                data[s * 2 + 1][1] = to + 1;
                data[s * 2 + 1][2] = -1;
            }
            data[n * 2][0] = 0;
            data[n * 2][1] = m;
            data[n * 2][2] = 0;
            Arrays.sort(data, Comparator.comparingLong(l -> l[1]));
            long cur = 1;
            long[][] mulTable = Matrix.i(3);
            long[] curOffsets = new long[3];
            long[] nextOffsets = new long[3];
            for (int i = 0; i < data.length; i++) {
                nextOffsets[(int) data[i][0]] += data[i][2];
                if (i == data.length - 1 || data[i][1] != data[i + 1][1]) {
                    long length = data[i][1] - cur;
                    if (length > 0) {
                        mulTable = Matrix.mulMod(mulTable, Matrix.pow(next(curOffsets), length));
                    }
                    curOffsets = Arrays.copyOf(nextOffsets, 3);
                    cur = data[i][1];
                }
            }
            out.println(Matrix.mulMod(new long[]{0, 1, 0}, mulTable)[1]);
        }

        private long[][] next(long[] offsets) {
            long[][] x = new long[][]{
                    {1, 1, 0},
                    {1, 1, 1},
                    {0, 1, 1}
            };
            for (int s = 0; s < 3; s++) {
                if (offsets[s] != 0) {
                    for (int l = 0; l < 3; l++) {
                        x[l][s] = 0;
                    }
                }
            }
            return x;
        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }

    static class Util {
        public static final long M07 = 1000_000_007;
        public static final long _m = M07;

    }

    static class Matrix {
        public static long[][] mulMod(long[][] l1, long[][] l2) {
            long[][] res = new long[l1.length][l2[0].length];
            for (int k1 = 0; k1 < l1.length; k1++) {
                for (int k2 = 0; k2 < l2[0].length; k2++) {
                    for (int inner = 0; inner < l1[0].length; inner++) {
                        res[k1][k2] += (l1[k1][inner] * l2[inner][k2] % Util._m);
                        if (res[k1][k2] >= Util._m) {
                            res[k1][k2] -= Util._m;
                        }
                    }
                }
            }
            return res;
        }

        public static long[] mulMod(long[] l2, long[][] l1) {
            return mulMod(new long[][]{l2}, l1)[0];
        }

        public static long[][] pow(long[][] v1, long md) {
            if (md == 0) {
                return i(v1.length);
            }
            if (md == 1) return v1;
            long[][] v2 = pow(v1, md / 2);
            v2 = mulMod(v2, v2);
            if (md % 2 == 1) {
                v2 = mulMod(v2, v1);
            }
            return v2;
        }

        public static long[][] i(int length) {
            long[][] res = new long[length][length];
            for (int s = 0; s < length; s++) {
                res[s][s] = 1;
            }
            return res;
        }

    }
}

