Segments in a Regular Polygon

Count the orders in which the remaining polygon vertices can be visited so each new segment crosses an existing one and the path closes back to P0.

Hard8BacktrackingDynamic programmingBit manipulationGeometryNo attempts yetTime limit2sMemory limit512 MB

Problem

Dohyun marked NN points on a sheet of paper to form a regular NN-gon. The vertices are numbered 11 through NN clockwise.

He then drew M1M-1 segments. He connected the vertices P0,P1,,PM1P_0, P_1, \dots, P_{M-1} in that order: P0P_0 to P1P_1, P1P_1 to P2P_2, and so on up to PM2P_{M-2} to PM1P_{M-1}.

Now he wants to keep drawing so that every remaining vertex is visited exactly once and the drawing returns to P0P_0. If the remaining vertices are visited in the order T0,T1,,TNM1T_0, T_1, \dots, T_{N-M-1}, he connects PM1P_{M-1} to T0T_0, T0T_0 to T1T_1, and so on up to TNM2T_{N-M-2} to TNM1T_{N-M-1}, and finally TNM1T_{N-M-1} to P0P_0. Every vertex that does not appear in PP appears in TT exactly once.

Every newly drawn segment must cross at least one segment that is already on the paper. The segments already on the paper include the ones drawn along PP and the ones drawn earlier in this process. Two segments cross when they share a point that lies in the interior of both, so two segments that share only an endpoint do not cross.

Given NN, MM, and PP, write a program that counts the possible orders TT.

Input

The first line contains NN and MM, separated by a space. (4N184 \le N \le 18, 2MN12 \le M \le N-1)

The second line contains the MM numbers P0P_0 through PM1P_{M-1} in order. Each number is between 11 and NN, and all of them are different.

Output

Print the number of possible orders TT on the first line.