시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB36151236.364%

문제

Given a permutation $A = (a_1, a_2, \dots, a_N)$ of the integers $1, 2, \dots, N$, we define the greedily increasing subsequence (GIS) in the following way.

Let $g_1 = a_1$. For every $i > 1$, let $g_i$ be the leftmost integer in $A$ that is strictly larger than $g_{i-1}$. If for a given $i$ there is no such integer, we say that the GIS of the sequence is the sequence $(g_1, g_2, ..., g_{i - 1})$.

For example, consider the permutation $(2, 3, 1, 5, 4, 7, 6)$. First, we have $g_1 = 2$. The leftmost integer larger than $2$ is $3$, so $g_2 = 3$. The leftmost integer larger than $3$ is $5$ ($1$ is too small), so $g_3 = 5$. Finally, $g_4 = 7$. Thus, the GIS of $(2, 3, 1, 5, 4, 7, 6)$ is $(2, 3, 5, 7)$.

Given a sequence $G = (g_1, g_2, \dots, g_L)$, how many permutations $A$ of the integers $1, 2, \dots, N$ have $G$ as its GIS?

입력

The first line of input contains the integers $1 \le N \le 10^6$, the number of elements of the permutation $A$, and $1 \le L \le 10^6$, the length of the sequence $G$.

The next line contains $L$ positive integers between $1$ and $N$, the elements $g_1, \dots, g_L$ of the sequence $G$.

출력

Output a single integer: the number of $N$-element permutations having the given sequence as its GIS. Since this number may be large, output it modulo the prime number $10^9 + 7$.

예제 입력 1

5 1
1

예제 출력 1

0

예제 입력 2

5 1
5

예제 출력 2

24

예제 입력 3

5 3
2 4 5

예제 출력 3

8

예제 입력 4

7 4
1 4 5 7

예제 출력 4

20