#include <bits/stdc++.h>
//#pragma GCC optimize("-Ofast")

#define int long long

using namespace std;

const int Mod = 998244353;

int binpow(int b, int p) {
    if (p == 0) return 1;
    if (p % 2 == 0) return binpow((b * b) % Mod, p / 2);
    return (binpow(b, p - 1) * b) % Mod;
}

int n, k;
vector<int> z, p, zT, sz, cz;
vector<pair<int, int>> zp;
vector<vector<int>> ch, dp;
vector<vector<pair<int, int>>> zch;

void dfst(int v, int cur = -1, int curt = -1) {
    if (zT[v] != -1) {
        if (cur == -1) cur = v;
        zp[zT[v]] = {cur, curt};
        cur = v;
    }
    for (int u : ch[v]) {
        if (zT[v] == -1) {
            dfst(u, cur, curt);
        } else {
            dfst(u, cur, u);
        }
    }
}

void dfsz(int v) {
    sz[v] = 1;
    for (int u : ch[v]) {
        dfsz(u);
        sz[v] += sz[u];
    }
}

void dfsc(int v) {
    if (zT[v] != -1) {
        cz[v]++;
    }
    for (int u : ch[v]) {
        cz[u] = cz[v];
        dfsc(u);
    }
}

void dfszor(int v, vector<int> &ans) {
    ans.push_back(z[v]);
    for (auto [u, _] : zch[v]) {
        dfszor(zT[u], ans);
    }
}

void dfsd(int v, int d, int &ans) {
    ans = max(ans, d);
    for (auto [u, _] : zch[v]) {
        dfsd(zT[u], d + 1, ans);
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> k;
    n++;
    z.resize(k);
    p.resize(n);
    zT.resize(n, -1);
    zp.resize(n);
    ch.resize(n);    
    for (int i = 0; i < k; i++) {
        cin >> z[i];
    }
    z.push_back(0);
    k++;
    for (int i = 0; i < k; i++) {
        zT[z[i]] = i;
    }
    p[1] = 0;
    ch[0].push_back(1);
    for (int i = 2; i < n; i++) {
        cin >> p[i];
        ch[p[i]].push_back(i);
    }

    dfst(0);

    zch.resize(n);
    for (int i = 0; i < k; i++) {
        if (zp[i].first != z[i]) {
            zch[zT[zp[i].first]].push_back({z[i], zp[i].second});
        }
    }

    vector<int> zor;
    dfszor(k - 1, zor);
    reverse(zor.begin(), zor.end());

    int dep = 0;
    dfsd(k - 1, 0, dep);

    sz.resize(n);
    dfsz(0);

    vector<int> mp(n), mpc(n);
    dp.resize(k, vector<int>(dep + 1));
    for (int alt = dep; alt >= 0; alt--) {
        for (int v : zor) {
            int tot = alt + 1;
            for (int u : ch[v]) {
                mp[u] = binpow(alt + 1, sz[u]);
                mpc[u] = sz[u];
            }
            for (auto [u, sb] : zch[zT[v]]) {
                mp[sb] = (mp[sb] * binpow(alt + 1, Mod - 1 - sz[u])) % Mod;
                mp[sb] = (mp[sb] * dp[zT[u]][alt + 1]) % Mod;
                mpc[sb] -= sz[u];
            }
            for (int u : ch[v]) {
                tot *= mp[u];
                tot %= Mod;
            }
            dp[zT[v]][alt] = tot;

            int prod = alt;
            for (int u : ch[v]) {
                mp[u] = binpow(alt, sz[u]);
            }
            for (auto [u, sb] : zch[zT[v]]) {
                mp[sb] = (mp[sb] * binpow(alt, Mod - 1 - sz[u])) % Mod;
                mp[sb] = (mp[sb] * dp[zT[u]][alt]) % Mod;
            }
            for (int u : ch[v]) {
                prod *= mp[u];
                prod %= Mod;
            }
            dp[zT[v]][alt] = (dp[zT[v]][alt] + Mod - prod) % Mod;

            for (int u : ch[v]) {
                mp[u] = (prod * binpow(alt, Mod - 1 - mpc[u])) % Mod;
                mp[u] = (mp[u] * binpow(alt + 1, mpc[u])) % Mod;
            }
            for (auto [u, sb] : zch[zT[v]]) {
                mp[sb] = (mp[sb] * binpow(dp[zT[u]][alt], Mod - 2)) % Mod;
                mp[sb] = (mp[sb] * dp[zT[u]][alt + 1]) % Mod;
            }
            for (int u : ch[v]) {
                dp[zT[v]][alt] = (dp[zT[v]][alt] + prod + Mod - mp[u]) % Mod;
            }
        }
    }

    int ans = dp[k - 1][0];
    cout << ans << "\n";
}
