#include <bits/stdc++.h>
/*#pragma GCC optimize("O3,unrool-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/
//#define int long long

using namespace std;
vector <int> idx;
int n,k;
vector <vector <int>> cn;
vector <int> a;
int ans=0;
    vector <vector <int> > can;
vector <int> da;
void f(int id) {
    if (id==n) {
        vector <vector<int>> cnt(n);
        for (int i=0; i<n; ++i) {
            if (idx[i]==-1)continue;
            cnt[idx[i]].push_back(i);
        }
        for (int i=0; i<k; ++i) {
            if (cnt[a[i]].empty()) {
                return;
            }
        }
        for (int i=0; i<k; ++i) {
            int et=a[i];
            for (int j=et+1; j<n; ++j) {
                bool fl=1;
                for (int id: cnt[et]) {
                    if (can[id][j]==0) {
                        fl=0;
                        break;
                    }
                }
                if (fl) {
                    return;
                }
            }
        }
        ans++;
        /*for (int i=0; i<n; ++i) {
            cout <<idx[i] <<" ";
        }
        cout <<'\n';*/
        return;
    }
    for (int i: cn[id]) {
        if (!da[i])continue;
        idx[id]=i;
        f(id+1);
    }
    idx[id]=-1;
    f(id+1);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >>n >>k;
    a.resize(k);
    da.resize(n);
    for (int i=0; i<k; ++i) {
        cin >>a[i];
        a[i]--;
        da[a[i]]=1;
    }
    vector <int> p(n);
    for (int i=1; i<n; ++i) {
        cin >>p[i];
        p[i]--;
    }
    can.resize(n, vector <int>(n));
    cn.resize(n);
    for (int i=0; i<n; ++i) {
        int id=i;
        can[i][id]=1;
        cn[i].push_back(id);
        while (p[id]!=id) {
            id=p[id];
            can[i][id]=1;
            cn[i].push_back(id);
        }
    }
    idx.resize(n);
    f(0);
    cout <<ans;
}
