시간 제한메모리 제한제출정답맞힌 사람정답 비율
3.5 초 1024 MB42211947.500%

문제

Some time ago, President K had a string $S$ of length $N$ consisting of lower case characters. But, he forgot it. He had a dictionary which contains misspellings of several kinds, and he once took a look at the dictionary to check the misspellings of the string $S$. Now, he remembers that the following is true for the string $S$.

  • Let $T_i$ ($1 ≤ i ≤ N$) be the string obtained from $S$ by deleting the $i$-th character and removing the gap. For each $j$ ($1 ≤ j ≤ M$), the relation $T_{A_j} ≤ T_{B_j}$ holds.

Here, $T_{A_j} ≤ T_{B_j}$ means either $T_{A_j}$ is equal to $T_{B_j}$, or $T_{A_j}$ is smaller than $T_{B_j}$ in the lexicographic order (alphabetical order).

Write a program which, given information on the string $S$ remembered by President K, calculates the number of strings $S$ modulo $1\,000\,000\,007$ which do not contradict given information.

입력

Read the following data from the standard input. Given values are all integers.

$\begin{align*} & N \, M \\ & A_1 \, B_1 \\ & A_2 \, B_2 \\ & \vdots \\ & A_M\, B_M \end{align*}$

출력

Write one line to the standard output. The output should contain the number of strings $S$ modulo $1\,000\,000\,007$ which do not contradict given information.

제한

  • $2 ≤ N ≤ 500\,000$.
  • $1 ≤ M ≤ 500\,000$.
  • $1 ≤ A_j ≤ N$ ($1 ≤ j ≤ M$).
  • $1 ≤ B_j ≤ N$ ($1 ≤ j ≤ M$).
  • $A_j \ne B_j$ ($1 ≤ j ≤ M$).
  • $(A_j , B_j) \ne (A_k, B_k)$ ($1 ≤ j < k ≤ M$).

서브태스크

번호배점제한
18

$N ≤ 10$.

220

$N ≤ 200$.

329

$M = N - 1$. Moreover, there exists a permutation $P$ of $(1, 2, \dots , N)$ of length $N$ satisfying $A_j = P_j$ and $B_j = P_{j+1}$ ($1 ≤ j ≤ M$).

432

$N ≤ 20\,000$.

511

No additional constraints.

예제 입력 1

3 2
1 3
3 2

예제 출력 1

5876

For example, if the string $S$ is bab, we have $T_1 = $ab, $T_2 = $bb, $T_3 = $ba. The relations $T_1 ≤ T_3$ and $T_3 ≤ T_2$ hold. This string does not contradict given information. In total, there are $5876$ strings $S$ which do not contradict given information. Therefore, output $5876$.

On the other hand, for example, if the strings $S$ is aab, we have $T_1 = $ab, $T_2 = $ab, $T_3 = $aa. The relation $T_1 ≤ T_3$ does not hold. Therefore, this string contradicts given information.

This sample input satisfies the constraints of all the subtasks.

예제 입력 2

5 6
1 2
1 5
2 4
5 4
5 3
4 3

예제 출력 2

656981

This sample input satisfies the constraints of Subtasks 1, 2, 4, 5.

예제 입력 3

10 9
3 6
4 6
6 7
7 9
10 8
9 8
8 5
5 2
5 1

예제 출력 3

206289833

The number of strings $S$ which do not contradict given information is $824\,206\,295\,601$. Therefore, output $206\,289\,833$, which is the remainder of $824\,206\,295\,601$ when divided by $1\,000\,000\,007$.

This sample input satisfies the constraints of Subtasks 1, 2, 4, 5.

예제 입력 4

7 6
1 3
3 4
4 6
6 5
5 7
7 2

예제 출력 4

7125651

This sample input satisfies the constraints of all the subtasks.

예제 입력 5

5 4
2 4
4 3
3 5
5 1

예제 출력 5

61451

This sample input satisfies the constraints of all the subtasks.

채점 및 기타 정보

  • 예제는 채점하지 않는다.