#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("avx2")

#define int long long
#define pb push_back
#define all(x) x.begin(), x.end();
#define rall(x) x.rbegin(), x.rend();
#define ff first
#define ss second
#define itn int
#define Auto auto

const int maxn = 2e5 + 10;
const int logn = 21;
const int B = 300;
const int inf = 4e18;
const int mod = 1e9 + 7;
const int mod1 = 998244353;

#ifdef LOCAL
#define debug(x) cerr << (#x) << ": " << x << endl;
#define debugv(x) cerr << (#x) << ": " << "[ "; for(auto t : x){cerr << t << ' ';} cerr << "]" << endl;
#endif


vector<vector<int> > g;
int up[logn][maxn];
vector<int> tin, tout;
int timer = 0;

void dfs(int v, int p) {
    up[0][v] = p;
    for (int i = 1; i < logn; ++i) {
        up[i][v] = up[i - 1][up[i - 1][v]];
    }
    tin[v] = timer;
    ++timer;
    for (auto to: g[v]) {
        if (to == p)
            continue;
        dfs(to, v);
    }
    tout[v] = timer;
}

bool upper(int a, int b) {
    return tin[a] <= tin[b] && tout[b] <= tout[a];
}

int lca(int a, int b) {
    if (upper(a, b)) {
        return a;
    }
    if (upper(b, a)) {
        return b;
    }
    for (int i = logn - 1; i >= 0; --i) {
        if (!upper(up[i][a], b)) {
            a = up[i][a];
        }
    }
    a = up[0][a];
    return a;
}

int binpow(int x, itn y) {
    if (y == 0) {
        return 1ll;
    }
    if (y % 2 == 0) {
        int bas = binpow(x, y / 2) % mod1;
        return bas * bas % mod1;
    } else {
        return (x * binpow(x, y - 1) % mod1) % mod1;
    }
}

vector<vector<itn> > mask;

bool into(int el, vector<int> &a) {
    for (auto t: a) {
        if (t == el) {
            return true;
        }
    }
    return false;
}

int ans = 0;
vector<int> c;

void rec(int n, int k, int cnt = 0) {
    if (cnt == k) {
        //debug(mask.size())
        for (itn i = 0; i < k; ++i) {
            auto t = mask[i];
            int lc = t[0];
            for (auto x: t) {
                lc = lca(lc, x);
            }
            //debug(lc)
            //debug(c[i])
            if (lc != c[i] - 1) {
                return;
            }

        }
        ans++;
        return;
    }
    for (int j = 1; j <= (1 << n); ++j) {
        bool fl = false;
        for (int i = 0; i < n; ++i) {
            if ((j >> i) & 1) {
                for (auto &t: mask) {
                    if (into(i, t)) {
                        fl = true;
                        break;
                    }
                }
                if (fl) {
                    break;
                }
            }
        }
        vector<int> cur;
        if (!fl) {
            for (int i = 0; i < n; ++i) {
                if ((j >> i) & 1) {
                    cur.pb(i);
                }
            }
        }
        if ((int) cur.size() > 0) {
            mask.pb(cur);
            rec(n, k, cnt + 1);
            mask.pop_back();
        }
    }
}

void solve() {
    int n, k;
    cin >> n >> k;
    g.resize(n);
    tin.resize(n);
    tout.resize(n);
    c.resize(k);
    for (auto &x: c) {
        cin >> x;
    }
    for (int i = 0; i < n - 1; ++i) {
        int x;
        cin >> x;
        g[x - 1].pb(i + 1);
        g[i + 1].pb(x - 1);
    }
    dfs(0, 0);
    rec(n, k);
    cout << ans;
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0ll;
}
