import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

public class army_sm_slow {
    int n;

    static class State {
        int[] mask;
        int completed;

        State(int[] mask, int completed) {
            this.mask = mask;
            this.completed = completed;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof State)) return false;

            State state = (State) o;

            if (completed != state.completed) return false;
            if (!Arrays.equals(mask, state.mask)) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = mask != null ? Arrays.hashCode(mask) : 0;
            result = 31 * result + completed;
            return result;
        }

        @Override
        public String toString() {
            return "State{" +
                    "mask=" + Arrays.toString(mask) +
                    ", completed=" + completed +
                    '}';
        }
    }

    final int FREE = 0;
    final int USED = 1;
    final int IN_A = 2;
    Map<State, Long> currentAnswer;
    Queue<State> queue;

    int[] a;

    void solve() throws IOException {
        n = nextInt();
        int k = nextInt();
        a = new int[k];
        for (int i = 0; i < k; i++) {
            a[i] = nextInt() - 1;
        }
        queue = new ArrayDeque<State>();
        currentAnswer = new HashMap<State, Long>();
        State start = new State(new int[n], 0);
        currentAnswer.put(start, 1L);
        queue.add(start);
        while (!queue.isEmpty()) {
            State s = queue.poll();
            long add = currentAnswer.get(s);
            System.err.println(" s = " + s + " ans = " + add);
            int[] armyt = new int[n + 1];
            int armytLen = 0;
            for (int i = 0; i < n; i++) {
                if (s.mask[i] == IN_A) {
                    armyt[armytLen++] = i;
                }
            }
            armyt[armytLen++] = n + 1;
            armyt = Arrays.copyOf(armyt, armytLen);
            for (int i = 0; i < n; i++) {
                if (s.mask[i] != FREE) {
                    continue;
                }
                for (int j = 0; j < armytLen; j++) {
                    if ((j == 0 || armyt[j - 1] < i) && i < armyt[j]) {
                        int[] newMask = s.mask.clone();
                        if (armyt[j] != n + 1) {
                            assert newMask[armyt[j]] == IN_A;
                            newMask[armyt[j]] = USED;
                        }
                        newMask[i] = IN_A;
                        int newCompleted = s.completed + ((s.completed < a.length && i == a[s.completed]) ? 1 : 0);
                        State newState = new State(newMask, newCompleted);
                        if (!currentAnswer.containsKey(newState)) {
                            currentAnswer.put(newState, 0L);
                            queue.add(newState);
                        }
                        currentAnswer.put(newState, currentAnswer.get(newState) + add);
                    }
                }

            }
        }
        long ans = 0;
        for (Map.Entry<State, Long> e : currentAnswer.entrySet()) {
            boolean completed = true;
            int inLasCnt = 0;
            for (int i : e.getKey().mask) {
                completed &= i != FREE;
                if (i == IN_A) {
                    inLasCnt++;
                }
            }
            if (completed && e.getKey().completed == a.length && inLasCnt == a.length) {
//                System.err.println("add "+ e);
                ans += e.getValue();
            }
        }
        System.out.println(ans);
        out.println(ans);
    }

    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    void run() throws IOException {
        br = new BufferedReader(new FileReader("army.in"));
        out = new PrintWriter("army.out");
        solve();
        out.close();
    }

    int nextInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        new army_sm_slow().run();
    }

}
