#include<iostream>
#include<vector>
#pragma GCC optimize("Ofast")
using namespace std;

using ll = long long;
using ld = long double;

const ll infl = (ll)4e18 + 100;
const int infi = (int)1e9 + 100;
const int maxn = (int)1e6 + 10;
const int mod = 998244353;

int n, k, x[maxn];
int p[maxn];

vector<int> g[maxn];

int tim = 0;
int tin[maxn];
int tout[maxn];
int d[maxn];

inline void dfs(int v) {
    tin[v] = tim++;
    for (auto& u : g[v]) {
        d[u] = d[v] + 1;
        dfs(u);
    }
    tout[v] = tim++;
}

inline bool unc(int u, int v) {
    return (tin[u] < tin[v] && tout[u] > tout[v]);
}

int bp[maxn][20];

inline int lca(int u, int v) {
    if (d[u] > d[v])
        swap(u, v);

    if (unc(u, v))
        return u;

    for (int K = 20 - 1; K >= 0; --K) {
        int w = bp[v][K];
        if (!unc(w, u))
            v = w;
    }

    return bp[v][0];
}

int task[maxn];
int lc[maxn];
int ans = 0;

inline void gen(int ps) {
    if (ps == n) {
        for (int i = 0; i < k; ++i)
            lc[i] = -1;

        for (int i = 0; i < n; ++i) {
            if (task[i] != -1) {
                if (lc[task[i]] == -1)
                    lc[task[i]] = i;
                else
                    lc[task[i]] = lca(lc[task[i]], i);
            }
        }

        // for (int i = 0; i < n; ++i)
        //     cout << task[i] << " ";
        // cout << '\n';
        // for (int i = 0; i < k; ++i)
        //     cout << lc[i] << " ";
        // cout << '\n';
        // for (int i = 0; i < k; ++i)
        //     cout << x[i] << " ";
        // cout << "\n------------\n";

        for (int i = 0; i < n; ++i)
            if (x[i] != lc[i])
                return;

        ans = (ans + 1) % mod;
        return;
    }

    for (int i = -1; i < k; ++i) {
        task[ps] = i;
        gen(ps + 1);
    }
}

inline void solve() {
    cin >> n >> k;
    for (int i = 0; i < k; ++i)
        cin >> x[i], --x[i];
    for (int i = 1; i < n; ++i)
        cin >> p[i], --p[i];


    for (int i = 1; i < n; ++i)
        g[p[i]].emplace_back(i);

    // for (int v = 0; v < n; ++v) {
    //     cout << v + 1 << ": ";
    //     for (auto& u : g[v])
    //         cout << u + 1 << " ";
    //     cout << '\n';
    // }

    d[0] = 0;
    dfs(0);

    for (int v = 0; v < n; ++v)
        bp[v][0] = p[v];

    for (int K = 1; K < 20; ++K)
        for (int v = 0; v < n; ++v)
            bp[v][K] = bp[bp[v][K - 1]][K - 1];

    // for (int K = 0; K < 20; ++K) {
    //     cout << K << ": ";
    //     for (int v = 0; v < n; ++v)
    //         cout << bp[v][K] << " ";
    //     cout << '\n';
    // }


    gen(0);
    cout << ans;
}

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

    int t_ = 1; // cin >> t_;
    while (t_--) {
        solve();
        cout << '\n';
    }

    return 0;
}