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

using namespace std;

#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define seta(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define all(a) (a).begin(), (a).end()

const string name = "army";

vector <int> p, now;
int n, m, ans;
map < vector <int>, int > M;
vector < vector <int> > good;

void calc()
{
	int armyt, ok, best = 0;
	good.clear();
	forn(i, 1 << n)
	{
		ok = 1, armyt = -1;
		now.clear();
		forn(j, n)
			if (i & (1 << j))
			{
				if (p[j] <= armyt)
				{
					ok = 0;
					break;
				}
				armyt = p[j];
				now.pb(armyt);
			}
		if (ok)
		{
			good.pb(now);
			best = max(best, (int) now.size());
		}
	}

	forn(i, good.size())
		if (good[i].size() == best)
		{
			now = good[i];
			if (!M.count(now)) M[now] = 0;
			M[now]++;
		}
}

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

	cin >> n;
	p.resize(n);
	forn(i, n)
		p[i] = i;
	M.clear();
	ans = 0;
	while (true)
	{
		calc();
		if (!next_permutation(all(p))) break;
	}

	cin >> m;
	p.resize(m);
	forn(i, m)
	{
		cin >> p[i];
		p[i]--;
	}
	cout << M[p] << endl;
	cerr << clock() << endl;

	return 0;
}
