#include <bits/stdc++.h>
#define int long long

using namespace std;

vector <vector <int>> g;
vector <vector <int>> pr;
vector <int> is;

void dfs(int v) {
    if (is[v]) pr[v].push_back(v);
    for (int to : g[v]) {
        pr[to] = pr[v];
        dfs(to);
    }
}

int n, k;
vector <int> arr;
vector <int> isv;

int dfs_lca(int v, int need) {
    int cnt = isv[v];
    for (int to : g[v]) {
        int get = dfs_lca(to, need);
        if (get >= n) return get;
        cnt += get;
    }
    if (cnt == need) return n + v;
    return cnt;
}

int find_lca(vector <int> &vec) {
    isv.clear();
    isv.resize(n);
    for (int x : vec) {
        isv[x] = 1;
    }
    return dfs_lca(0, vec.size()) - n;
}

int ans = 0;

vector <int> color;

void go() {
    if (color.size() == n) {
        vector <vector <int>> colors(n);
        for (int i = 0; i < n; ++i) {
            if (color[i] != -1) colors[color[i]].push_back(i);
        }
        int ck = 0;
        for (int i = 0; i < n; ++i) {
            if (!colors[i].empty()) {
               int lca = find_lca(colors[i]);
               if (lca != i) return;
               ck++;
            }
        }
        ans += (ck == k);
        return;
    }
    int i = color.size();
    color.push_back(-1);
    go();
    color.pop_back();
    for (int p : pr[i]) {
        color.push_back(p);
        go();
        color.pop_back();
    }
}

signed main() {
    cin >> n >> k;
    arr.resize(k);
    g.resize(n);
    pr.resize(n);
    is.resize(n);
    for (int i = 0; i < k; ++i) {
        cin >> arr[i];
        arr[i]--;
        is[arr[i]] = 1;
    }
    for (int i = 1; i < n; ++i) {
        int p;
        cin >> p;
        g[p - 1].push_back(i);
    }
    dfs(0);
    go();
    cout << ans << endl;
    return 0;
}
