#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using pii = pair<int, int>;


const int MOD = 998244353;


void dfs(int u, vector<int> &sz, vector<vector<int>> &g) {
    for (auto v : g[u]) {
        dfs(v, sz, g);
        sz[u] += sz[v];
    }
}

void dfs2(int u, vector<vector<int>> &g, int &reach) {
    reach += (1 << u);
    for (auto v : g[u]) {
        dfs2(v, g, reach);
    }
}




void solve() {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> g(n);
    vector<int> qs(q);
    sort(all(qs));
    for (int i = 0; i < q; i++) {
        cin >> qs[i];
        qs[i]--;
    }
    for (int i = 1; i < n; i++) {
        int p; cin >> p; p--;
        g[p].push_back(i);
    }
    vector<int> lca((1 << n), -1);

    for (int mask = 1; mask < (1 << n); mask++) {
        for (int u = n - 1; u >= 0; u--) {
            int reach = 0;
            dfs2(u, g, reach);
            if ((reach & mask) == mask) {
                lca[mask] = u;
                break;
            }
        }
    }

    vector<int> dp((1 << n));
    dp[0] = 1;
    for (int k = 0; k < q; k++) {
        vector<int> dp2((1 << n));
        for (int mask = 1; mask < (1 << n); mask++) {
            for (int mask2 = 1; mask2 < (1 << n); mask2++) {
                if ((mask2 & mask) != mask2) continue;
                if (lca[mask2] == qs[k]) {
                    dp2[mask] += dp[mask ^ mask2];
                }
            }
        }
        dp = dp2;
    }
    int ans = 0;
    for (int mask = 1; mask < ( 1 << n); mask++) {
        ans += dp[mask];
    }
    cout << ans;

    

}


signed main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

}