#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
using ll = long long;
//using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;


/*
struct segtree{
    vector<ll> tree;
    ll sz;
    ll def = 0;
    ll merg(ll a, ll b) {
        return a + b;
    }
    void clar(ll n) {
        tree.assign(4 * n, def);
        sz = n;
    }
    segtree() {

    }
    void build(ll v, ll l, ll r, vector<ll> & a) {
        if (r - l == 1) {
            tree[v] = a[l];
            return;
        }
        ll m = (l + r) / 2;
        build(v * 2 + 1, l, m, a);
        build(v * 2 + 2, m, r, a);
        tree[v] = merg(tree[v * 2 + 1], tree[v * 2 + 2]);
    }
    segtree(vector<ll> & a) {
        ll n = (ll)a.size();
        clar(n);
        build(0, 0, sz, a);
    }
};
*/

ll mod = 998244353;

ll po(ll x, ll n) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 0) {
        ll c = po(x, n / 2);
        return (c * c) % mod;
    } else {
        return (x * po(x, n - 1)) % mod;
    }
}

ll n;
vector<ll> good;
vector<vector<ll>> g;


vector<vector<ll>> ans;
vector<ll> st;

void dfs(ll u, ll p = -1) {
    if (good[u]) {
        st.push_back(u);
    }
    ans[u] = st;
    for (auto v : g[u]) {
        if (v != p) {
            dfs(v, u);
        }
    }
    if (good[u]) {
        st.pop_back();
    }
}

vector<set<ll>> se;
ll fl = 1;

void dfs1(vector<ll> & color, ll u, ll p = -1) {
    ll cnt = 0;
    se[u].insert(color[u]);
    if (se[u].find(u) != se[u].end()) {
        cnt += 2;
    }
    for (auto v : g[u]) {
        if (v != p) {
            dfs1(color, v, u);
            if (se[v].find(u) != se[v].end()) {
                cnt++;
            }
            for (auto i : se[v]) {
                se[u].insert(i);
            }
        }
    }
    if (good[u] && cnt < 2) {
        fl = 0;
    }
}


bool goo(vector<ll> & color) {
    se.resize(n);
    for (auto & i : se) {
        while (i.size()) {
            i.erase(i.begin());
        }
    }
    fl = 1;
    dfs1(color, 0);
    return fl;
}

ll otv = 0;

void rec(ll cnt, vector<ll> & cur) {
    if (cnt == n) {
        if (goo(cur)) {
            otv++;
        }
        return;
    }
    for (auto i : ans[cnt]) {
        cur.push_back(i);
        rec(cnt + 1, cur);
        cur.pop_back();
    }
}

void solve() {
    ll k;
    cin >> n >> k;
    good.assign(n, 0);
    g.assign(n, {});
    ans.assign(n, {});
    for (ll i = 0; i < k; i++) {
        ll x;
        cin >> x;
        x--;
        good[x] = 1;
    }
    for (ll i = 1; i < n; i++) {
        ll v;
        cin >> v;
        v--;
        g[i].push_back(v);
        g[v].push_back(i);
    }
    st.resize(0);
    dfs(0);
    for (auto &i : ans) {
        i.push_back(-1);
    }
    vector<ll> col;
    rec(0, col);
    cout << otv << endl;
}

signed main() {
    int MULTITEST = 0;
    #ifdef zapvm
        MULTITEST = 1;
        freopen("in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    if (MULTITEST) {
        cin >> t;
    }
    while (t--) {
        solve();
    }
}