#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

void fast_in_out() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(18) << fixed;
#ifdef LOCAL
    freopen("input.txt", "r",stdin);
    freopen("output.txt", "w",stdout);
#endif
}

typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define all(x) (x).begin(), (x).end()
// #define int long long
using ll = long long;
const int N = 10, mod = 998244353;
int n, m, a[N];
vector<int> g[N], p[N], d;
int lc[N][N];

vector<int> dfs(int v) {
    if (a[v]) {
        d.emplace_back(v);
    }
    p[v] = d;
    vector<int> h = {v};
    for (auto to: g[v]) {
        auto h1 = dfs(to);
        for (auto i: h1) {
            h.emplace_back(i);
        }
    }
    for (auto it: h) {
        for (auto it1: h) {
            if (lc[it][it1] == -1) {
                lc[it][it1] = v;
                lc[it1][it] = v;
            }
        }
    }
    if (a[v]) {
        d.pop_back();
    }
    return h;
}

int lca(int q, int w) {
    return lc[q][w];
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            lc[i][j] = -1;
        }
    }
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        --x;
        a[x] = 1;
    }
    for (int i = 1; i < n; ++i) {
        int x;
        cin >> x;
        --x;
        g[x].emplace_back(i);
    }
    dfs(0);
    int ans = 0, F = 1;
    for (int i = 0; i < n; ++i) {
        F *= (int) p[i].size() + 1;
    }
    for (int f = 0; f < F; ++f) {
        vector<int> vec[n];
        int f1 = f;
        for (int i = 0; i < n; ++i) {
            int pos = f1 % ((int) p[i].size() + 1);
            f1 /= (int) p[i].size() + 1;
            if (pos != (int) p[i].size()) {
                vec[p[i][pos]].emplace_back(i);
            }
        }
        int ok = 1;
        for (int i = 0; i < n; ++i) {
            if (a[i]) {
                if (vec[i].empty()) {
                    ok = 0;
                    break;
                }
                int l = vec[i][0];
                for (auto it: vec[i]) {
                    l = lca(l, it);
                }
                if (l != i) {
                    ok = 0;
                    break;
                }
            }
        }
        if (ok) {
            ++ans;
        }
    }
    cout << ans;
}


signed main() {
    fast_in_out();
    int qwe = 1;
    // cin >> qwe;
    while (qwe--) {
        solve();
    }
}
