Very Long Suffix Array TASUFFIX

All submissions for this problem are available.<p> Let S = s1, s2, …,sn be a string and let S[i, j] denote the substring si, si+1, … sj. The suffix array A of S is an array of integers giving the starting positions of suffixes of S in lexicographical order. This means, the entry A[i] contains the starting position of the i-th smallest(lexicographically) suffix of S. In other words, for all 1 < i ≤ n: S[A[i - 1], n] < S[A[i], n].</p>

Let us take an example. Suppose S = "12323". Then all suffixes of S are "12323", "2323", "323", "23", "3". If we sort the suffixes lexicographically, we get "12323", "23", "2323", "3", "323". Therefore the suffix array, which gives the starting positions of suffixes in lexicographic order, will be A = 1, 4, 2, 5, 3.

There is exactly one suffix array for each string. However, several strings can give the same suffix array. In this problem, given a suffix array A of length N, you have to calculate the number of strings S whose suffix array is A.

However, N can be very large, so the array A is not given directly. You should initialize the array A as A[i] = i for all 1 ≤ i ≤ N and apply M operations to it in order to obtain the desired suffix array A. Each operation can be of one of the following types:

For this problem, a string is an array of positive integers. Additionally, the number of different integers used in a string must be same as the largest integer in the string. For example: (1, 2, 2) and (4, 5, 1, 2, 3) are valid strings while (1, 1, 3) and (-1, 0, 1, 2) are not.

Since the result can be extremely large, you just have to print it modulo 1,000,000,007(109 + 7)

Input

The first line of the input contains 2 space separated integers, N and M. N is the length of suffix array, and M is the number of operations.
Each of the next M lines contains 3 space separated integers representing an operation of one of the two types.

Output

Output a single line containing the number of strings corresponding to the given suffix array modulo 1,000,000,007(109 + 7) .

Constraints

Example

Input:
4 2
1 2 3
0 3 4
Output:
4

Explanation

The initial array is (1, 2, 3, 4).
After the first operation the array becomes (1, 3, 2, 4).
After the second operation the array becomes (2, 4, 1, 3).
The 4 possible strings are (2, 1, 2, 2), (2, 1, 3, 2), (3, 1, 3, 2), (3, 1, 4, 2).