#include <bits/stdc++.h>
using namespace std;


#define int long long
#define line cout << "\n"
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>

typedef string str;
typedef long long ll;
typedef long double ld;
const int MOD = 998244353;
const int MAXN = 10 + 1;
vector<int> g[MAXN];


int bpow(int a, int b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2) {
        return bpow(a, b - 1) * a % MOD;
    }
    int t = bpow(a, b / 2);
    return t * t % MOD;
}


int pr[MAXN];
void calc(int v) {
    pr[v] = 1;
    for (auto &u : g[v]) {
        calc(u);
        pr[v] += pr[u];
    }
}

bool f = false;
int good[MAXN];

int check(int v, bool f) {
    int cnt = good[v];
    int cnt_ma = 0;
    for (auto &u : g[v]) {
        int x = check(u, false);
        cnt_ma = max(cnt_ma, x);
        cnt += x;
    }
    if (f && cnt_ma == cnt) {
        return -1;
    }
    return cnt;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(k);
    for (auto &u : a) {
        cin >> u;
        u--;
    }
    for (int i = 1; i < n; i++) {
        int v;
        cin >> v;
        g[v - 1].pb(i);
    }
    calc(0);
    vector<vector<int>> dp(k + 1, vector<int>(1 << n));
    dp[0][0] = 1;
    for (int i = 0; i < k; i++) {
        for (int mask = 0; mask < (1 << n); mask++) {
            for (int mask2 = 0; mask2 < (1 << n); mask2++) {
                if ((mask & mask2) != mask2) {
                    continue;
                }
                int rzn = (mask ^ mask2);
                int c = 0;
                for (int j = 0; j < n; j++) {
                    if (rzn & (1 << j)) {
                        good[j] = 1;
                        c++;
                    }
                }
                int f = check(a[i], true);
                if (f == c) {
                    dp[i + 1][mask] = (dp[i + 1][mask] + dp[i][mask2]) % MOD;
                }
                for (int j = 0; j < n; j++) {
                    good[j] = 0;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        ans = (ans + dp[k][i]) % MOD;
    }
    cout << ans; line;
}


signed main() {
    ios_base::sync_with_stdio(false);
    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();
    }
}