
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
struct LCA {
    vvll g, lift;
    vll depth;
    LCA(vvll g) : g(g) {
        ll n = g.size();
        lift = vvll(20, vll(n, 0));
        depth = vll(n, -1);
        dfs(0, 0);
    }
    void dfs(ll v, ll pr) {
        lift[0][v] = pr;
        depth[v] = 1 + depth[pr];
        for (ll i = 1; i < 20; ++i) {
            lift[i][v] = lift[i - 1][lift[i - 1][v]];
        }
        for (ll u : g[v]) if (u != pr) dfs(u, v);
    }
    ll lca(ll v, ll u) {
        if (depth[v] < depth[u]) swap(v, u);
        for (ll i = 19; i >= 0; --i) {
            if (depth[lift[i][v]] >= depth[u]) v = lift[i][v];
        }
        if (v == u) return v;
        for (ll i = 19; i >= 0; --i) {
            if (lift[i][v] != lift[i][u]) v = lift[i][v], u = lift[i][u];
        }
        return lift[0][v];
    }
};
ll ans = 0;
void rec(ll i, ll n, ll k, vll& a, LCA& lca, vll& b) {
    if (i >= n) {
        for (ll i = 0; i < n; ++i) {
            if (!a[i]) continue;
            if (b[a[i]] != i) return;
        }
        ++ans;
        return;
    }
    for (ll j = 0; j <= k; ++j) {
        ll pr = b[j];
        if (b[j] == -1) b[j] = i;
        else b[j] = lca.lca(b[j], i);
        rec(i + 1, n, k, a, lca, b);
        b[j] = pr;
    }
}
void solve() {
    ll n, k;
    cin >> n >> k;
    vll a(n);
    for (ll i = 0; i < k; ++i) {
        ll x;
        cin >> x;
        --x;
        a[x] = i + 1;
    }
    vvll g(n);
    for (ll i = 1; i < n; ++i) {
        ll pr;
        cin >> pr;
        --pr;
        g[i].push_back(pr);
        g[pr].push_back(i);
    }
    LCA lca(g);
    vll b(k + 1, -1);
    rec(0, n, k, a, lca, b);
    cout << ans << endl;
}

int main() {
    //reopen("in.txt", "r", stdin);

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    cout << endl;
    return 0;
}
