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.util.*;
import java.io.* ;

public class Main
{
    static final int MOD = (int)1e9 + 7 ;

    static int [][] mult(int [][] A  , int [][] B)
    {
        int [][] C = new int [3][3] ;
        for(int i = 0 ; i < 3 ; i ++)
            for(int j = 0 ; j < 3 ; j++)
                for(int k = 0 ; k < 3 ; k++)
                {
                    C[i][j] += (int)(1L * A[i][k] * B[k][j] % MOD) ;
                    C[i][j] %= MOD ;
                }
        return C ;
    }
    static int [][] pow(int [][] A , long e)
    {
        int [][] ans = new int [3][3] ;
        for(int i = 0 ; i < 3 ; i ++) ans[i][i] = 1 ;

        while(e > 0)
        {
            if((e & 1) == 1)
                ans = mult(ans , A) ;
            A = mult(A , A) ;
            e >>= 1 ;
        }
        return ans ;
    }
    public static void main(String [] args) throws Exception
    {
        Scanner sc = new Scanner(System.in) ;
        PrintWriter out = new PrintWriter(System.out) ;
        int n = sc.nextInt() ;
        long m = sc.nextLong() ;

        int [] cnt = new int [3] ;

        Event [] events = new Event[n << 1] ;

        for(int i = 0 ; i < n ; i ++)
        {
            int a = sc.nextInt() - 1 ;
            long l = sc.nextLong() , r = sc.nextLong() ;
            events[i << 1] = new Event(1 , l , a) ;
            events[i << 1 | 1] = new Event(-1 , r , a) ;
        }
        Arrays.sort(events);
        long last = 1 ;
        int [][] ans = new int [3][3] ;
        for(int i = 0 ; i < 3 ; i ++)
            ans[i][i] = 1 ;
        int [][] T = new int [3][3] ;
        for(int i = 0 ; i < 3 ; i++)
            for(int j = 0 ; j < 3 ; j ++)
                if(i == j || (i > 0 && i - 1 == j) || (i < 2 && i + 1 == j))
                    T[i][j] = 1 ;

        for(Event e : events)
        {
            long curr = e.point ;
            ans = mult(ans , pow(T , curr - last)) ;
            cnt[e.row] += e.type ;
            T = new int [3][3] ;
            for(int i = 0 ; i < 3 ; i++)
                for(int j = 0 ; j < 3 ; j ++)
                    if((i == j || (i > 0 && i - 1 == j) || (i < 2 && i + 1 == j)) && cnt[j] == 0 && cnt[i] == 0)
                        T[i][j] = 1 ;
            last = curr ;
        }
        ans = mult(ans , pow(T , m - last));
        out.println(ans[1][1]);
        out.flush();
        out.close();
    }
    static class Event implements Comparable<Event>
    {
        int type , row;
        long point ;

        Event(int a , long b , int c) {type = a ; point = b ; row = c; }

        @Override
        public int compareTo(Event o)
        {
            if(point == o.point)
                return o.type - type ;
            return Long.compare(point , o.point);
        }
    }
    static class Scanner
    {
        BufferedReader br ;
        StringTokenizer st ;

        Scanner(InputStream in)
        {
            br = new BufferedReader(new InputStreamReader(in)) ;
        }

        String next() throws Exception
        {
            while(st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine()) ;
            return st.nextToken() ;
        }

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

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