#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define seta(a, b) memset(a, b, sizeof(a))

const string name = "army";

const int NMAX = 17;
int n, m, ans, num;
int used[NMAX], need[NMAX], d[NMAX], p[NMAX];

void rec()
{
	if (num == n)
	{
		ans++;
		return;
	}
	int yl = m + 1, x, y;
	for (int i = n - 1; i >=0; --i)
		if (!used[i] && used[need[i]])
		{
			while (d[yl - 1] >= i)
				--yl;
			if (yl <= m)
			{
				x = yl, y = d[yl];
				d[yl] = i;
				num++;
				used[i] = 1;
				rec();
				num--;
				used[i] = 0;
				d[x] = y;
			}
		}
}

int main()
{
	freopen((name + ".in").data(), "r", stdin);
	freopen((name + ".out").data(), "w", stdout);

	cin >> n >> m;
	forn(i, m)
	{
		cin >> p[i];
		p[i]--;
	}
	forn(i, n)
		need[i] = n;
	for (int i = 1; i < m; ++i)
		need[p[i]] = p[i - 1];

	num = ans = 0;
	seta(d, 1);
	d[0] = -1;
	seta(used, 0);
	used[n] = 1;
	rec();
	cout << ans << endl;
	cerr << clock() << endl;

	return 0;
}
