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

#define endl '\n'
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int mod = 998244353;

int add(int a, int b) {
    if (a + b >= mod) {
        return a + b - mod;
    } else {
        return a + b;
    }
}

int sub(int a, int b) {
    if (a < b) {
        return a - b + mod;
    } else {
        return a - b;
    }
}

int mul(int a, int b) {
    return 1ll * a * b % mod;
}

int binpow(int a, int b) {
    int ans = 1;
    while (b > 0) {
        if (b % 2) {
            ans = mul(ans, a);
        }
        a = mul(a, a);
        b /= 2;
    }
    return ans;
}

const int N = 11;
int dp[N][(1 << N)];
int lca[N][N];

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> x(k + 1), prev(n + 1);
    for (int i = 1; i <= k; i++) {
        cin >> x[i];
    }
    vector<vector<int>> g(n + 1);
    vector<int> sz(n + 1), tin(n + 1), tout(n + 1);
    for (int i = 2; i <= n; i++) {
        int p;
        cin >> p;
        prev[i] = p;
        g[p].push_back(i);
    }
    int time = 0;
    auto dfs = [&](int v, auto &&dfs) -> void {
        tin[v] = time++;
        for (auto u : g[v]) {
            dfs(u, dfs);
        }
        tout[v] = time++;
    };
    dfs(1, dfs);
    auto par = [&](int v, int u) {
        return tin[v] <= tin[u] && tout[u] <= tout[v];
    };
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (par(i, j)) {
                lca[i][j] = i;
            } else if (par(j, i)) {
                lca[i][j] = j;
            } else {
                int v = i;
                while (!par(v, j)) {
                    v = prev[v];
                }
                lca[i][j] = v;
            }
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= k; i++) {
        for (int mask = 0; mask < (1 << n); mask++) {
            for (int cur = mask + 1; cur < (1 << n); cur++) {
                if ((cur & mask) == mask) {
                    int now = cur ^ mask;
                    int v = -1;
                    for (int j = 0; j < n; j++) {
                        if ((now >> j) & 1) {
                            if (v == -1) {
                                v = j + 1;
                            } else {
                                v = lca[v][j + 1];
                            }
                        }
                    }
                    if (v == x[i]) {
                        dp[i][cur] = add(dp[i][cur], dp[i - 1][mask]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        ans = add(ans, dp[k][mask]);
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}