#WPC5F. Parade

Parade

It is the Annual Parade of the Galactical Wars. Great men and women from around the cosmos have come to view this spectacular event. To make this a special occasion, the leaders in galaxy H2 have decided to arrange his participants in a particularly beautiful order.

Firstly, they have chosen n particularly suited participants. These n participants have distinct heights ranging from 1 to n. They have arranged them in some way, so that the height of the ith student is H(i).

The sworn enemies of H2, galaxy H3 have obtained some secret information on this arrangement. They know that there is a set of elements A(containing total k indices), such that H(j) < H(j-1) IF AND ONLY IF j belongs to A. As a Martian on H3, your organizer asks you to find the number of such possible configurations that H2 could have made.

 

Input: 
A single line containing space separated integers: n and k
Next line containing k indices as explained in the problem.
Output:
A single line containing the number of ways to arrange participants modulo 1000000009 ( 10 ^ 9 + 9)
Constraints:
1 <= n <= 700
0 <= m <= n-1
2 <= i <= n (i is an index)
All i’s are unique.
Time Limit: 4 seconds.
Examples:
Input:
3 1
2
Output:
2
There are 2 possible ways to arrange the participants, where their heights are:
2 1 3 or 3 1 2
Note 3 2 1 is not a valid ordering since h(3) < h(2).

Input: 

A single line containing space separated integers: n and k

Next line containing k indices as explained in the problem.

 

Output:

A single line containing the number of ways to arrange participants modulo 1000000009 ( 10 ^ 9 + 9)

 

Constraints:

1 <= n <= 700

0 <= k <= n-1

2 <= i <= n (i is an index)

All i’s are unique.

 

Time Limit: 4 seconds.

 

Examples:

 

Input:

3 1

2

 

Output:

2

 

Explanation: There are 2 possible ways to arrange the participants, where their heights are:

2 1 3 or 3 1 2

 

Note 3 2 1 is not a valid ordering since h(3) < h(2).