#include <bits/stdc++.h>

#pragma gcc_optimize("O3", "unroll_loops")

// #define int long long

using namespace std;
using ll = long long;
using ld = long double;
using sll = __int128;

const int maxn = 1e6 + 10, mod = 998244353;

int h[maxn];
vector<int> g[maxn];
int n, k;

int pr[maxn];
int ans = 0;
vector<int> books;
void count_h(int vi, int p) {
    h[vi] = h[p] + 1;
    for (auto to : g[vi]) {
        if (to == p) continue;
        count_h(to, vi);
    }
}

pair<int, int> dfs(int vi, int p, unordered_set<int> &st) {
    int cnt = st.contains(vi);
    int res = 0;
    for (auto to : g[vi]) {
        if (to == p) continue;
        auto [lca, c] = dfs(to, vi, st);
        res = max(res, lca);
        cnt += c;
    }
    if (cnt == (int)st.size() && res == 0) res = vi;
    return {res, cnt};
}

void gen(int ind, vector<unordered_set<int>> vert) {
    if (ind > n) {
        bool fl = 1;
        for (int i = 0; i < k; i++) {
            if (vert[i].empty()) return;
            if (dfs(books[i], pr[books[i]], vert[i]).first != books[i]) fl = 0;
        }
        ans += fl;
        return;
    }
    gen(ind + 1, vert);
    for (int i = 0; i < k; i++) {
        if (h[ind] < h[books[i]]) continue;
        vert[i].insert(ind);
        gen(ind + 1, vert);
        vert[i].erase(ind);
    }
}

void solve() {
    cin >> n >> k;
    books.resize(k);
    for (int i = 0; i < k; i++) cin >> books[i];
    vector<unordered_set<int>> vert(k);
    for (int i = 2; i <= n; i++) {
        int p; cin >> p;
        pr[i] = p;
        g[p].push_back(i);
        g[i].push_back(p);
    }
    gen(1, vert);
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test = 1;
    // cin >> test;
    while (test--) {
        solve();
    }
}