Under construction

Still being built. Things may change

Segments in a Regular Polygon

Time limit2sMemory limit512 MB

Summary
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.
Level

Hard8 of 10

Topics
Backtracking, Dynamic programming, Bit manipulation, Geometry
Solved
No attempts yet

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 M−1M-1 segments. He connected the vertices P0,P1,…,PM−1P_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 PM−2P_{M-2} to PM−1P_{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,…,TN−M−1T_0, T_1, \dots, T_{N-M-1}, he connects PM−1P_{M-1} to T0T_0, T0T_0 to T1T_1, and so on up to TN−M−2T_{N-M-2} to TN−M−1T_{N-M-1}, and finally TN−M−1T_{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. (4≤N≤184 \le N \le 18, 2≤M≤N−12 \le M \le N-1)

The second line contains the MM numbers P0P_0 through PM−1P_{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.

Examples4

  1. Example 1

    Input
    5 3
    1 3 5
    
    Expected output
    1
    
  2. Example 2

    Input
    6 3
    1 4 2
    
    Expected output
    1
    
  3. Example 3

    Input
    7 3
    2 4 7
    
    Expected output
    2
    
  4. Example 4

    Input
    7 6
    1 2 3 4 6 5
    
    Expected output
    0