#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
#define ld long double
const int MOD = 998244353;
int n, k;
vector <int> x, p;
vector <int> r;
vector <vector <int>> can;
ll ans = 0;
void rec() {
	if (r.size() == n) {
		vector <int> a = r;
		//reverse(a.begin(), a.end());
		vector <vector <int>> v(k + 1);
		for (int i = 0; i < n; ++i)
			v[a[i]].push_back(i);
		for (int i = 1; i <= k; ++i)
			if (v[i].empty()) return;
		for (int i = 0; i < n; ++i) {
			if (x[a[i]] != -1 && can[i][x[a[i]] - 1] == 0) return;
		}
		for (int i = 1; i <= k; ++i) {
			int cur = x[i];
			for (int j = cur + 1; j <= n; ++j) {
				bool b = true;
				for (auto u : v[i]) {
					if(!can[u][j - 1]) {
						b = false;
						break;
					}
				}
				if (b) return;
			}
		}
		ans++;
		return;
	}
	for (int i = 0; i < k + 1; ++i) {
		if ((int)r.size() + 1 < x[i]) {
			//for (auto el : r) cout << x[el] << ' ';
			//cout << "\n";
			//cout << (int)r.size() + 1 << ' ' << x[i] << "\n";
			continue;
		}
		r.push_back(i);
		rec();
		r.pop_back();
	}
}
void solve() {
	cin >> n >> k;
	x.resize(k);
	p.resize(n, -1);
	can.assign(n, vector <int>(n));
	vector <vector <int>> g(n);
	for (int i = 0; i < k; ++i) cin >> x[i];
	x.push_back(-1);
	sort(x.begin(), x.end());
	for (int i = 1; i < n; ++i) {
		int v; cin >> v;
		v--;
		p[i] = v;
	}
	for (int i = 0; i < n; ++i) {
		int v = i;
		while (true) {
			can[i][v] = 1;
			if (p[v] == -1) break;
			v = p[v];
		}
	}
	rec();
	cout << ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
