#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>
#pragma GCC target("avx2")
//#define int long long

using namespace std;
const int INF = 1e9;
const int mod = 998244353;
const int LG = 20;

void dfs(int v, vector <vector<int>> &g, vector <int> &h, int t) {
    h[v] = t;

    for (auto i : g[v]) {
        dfs(i, g, h, t + 1);
    }
}

vector <int> h;
vector <vector<int>> binUp;

int lca(int u, int v) {
    if (h[v] < h[u]) {
        swap(u, v);
    }

    for (int i = LG - 1; i >= 0; --i) {
        if (h[binUp[v][i]] >= h[u]) {
            v = binUp[v][i];
        }
    }

    if (v == u) {
        return v;
    }

    for (int i = LG - 1; i >= 0; --i) {
        if (binUp[u][i] != binUp[v][i]) {
            v = binUp[v][i];
            u = binUp[u][i];
        }
    }

    return binUp[v][0];
}

int ans = 0;

void rec(int j, vector <int> a, vector <int> x, int n, int k) {
    if (j == n) {
        vector <vector<int>> p(k);
        for (int i = 0; i < n; ++i) {
            if (a[i] < k) {
                p[a[i]].push_back(i);
            }
        }

        bool f = true;
        for (int i = 0; i < k; ++i) {
            if (p[i].empty()) {
                f = false;
                break;
            }

            int v = p[i].front();
            for (auto t : p[i]) {
                v = lca(t, v);
            }

            if (v != x[i]) {
                f = false;
            }
        }

        if (f) {
            ans++;
        }

        return;
    }

    for (int i = 0; i <= k; ++i) {
        a.push_back(i);
        rec(j + 1, a, x, n, k);
        a.pop_back();
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;

    vector <int> x(k);

    for (int i = 0; i < k; ++i) {
        cin >> x[i];
        x[i]--;
    }

    vector <int> p(n);
    vector <vector<int>> g(n);
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;

        g[p[i]].push_back(i);
    }

    binUp.resize(n, vector <int> (LG));
    for (int i = 0; i < n; ++i) {
        binUp[i][0] = p[i];
    }
    h.resize(n);
    for (int l = 1; l < LG; ++l) {
        for (int i = 0; i < n; ++i) {
            binUp[i][l] = binUp[binUp[i][l - 1]][l - 1];
        }
    }


    dfs(0, g, h, 0);

    rec(0, {}, x, n, k);

    cout << ans << "\n";

    return 0;
}