#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
using ll = int;
const ll mod = 998244353;

bool check(ll n, ll k, vector<ll> &mask, vector<ll> &xx, vector<ll> &p) {
    vector<bool> used(n);
    vector<vector<ll>> pos(k);
    for (ll j = 0; j < k; j++) {
        auto m = mask[j];
        for (ll i = 0; i < n; i++) {
            if ((1 << i) & m) {
                if (used[i]) return false;
                pos[j].push_back(i);
                used[i] = 1;
            }
        }
    }
    for (ll i = 0; i < k; i++) {
        vector<ll> cnt(n);
        ll x = xx[i];
        if ((ll) pos[i].size() == 0) return false;
        if ((ll) pos[i].size() == 1 && pos[i][0] != x) return false;
        else if (pos[i].size() == 1) continue;
        for (ll j : pos[i]) {
            ll cur = j;
            bool flag = 0;
            if (cur == x) flag = 1;
            while (cur != x && cur > 0) {
                cnt[cur]++;
                cur = p[cur];
                if (cur == x) flag = 1;
            }
            // if (!flag) cout << 77 << '\n';
            if (!flag) return false;
        }
        for (ll j = 0; j < n; j++) {
            if (p[j] == x && cnt[j] == (ll) pos[i].size()) return false;
        }
    }
    // cout << mask[0] << '\n';
    return true;
}

long long ans = 0;

void rec(ll ind, ll n, ll k, vector<ll> &xx, vector<ll> &mask, vector<ll> &p) {
    if (ind == k) {
        ans = ans + check(n, k, mask, xx, p);
        return;
    }
    for (ll m = 1; m < (1 << n); m++) {
        mask.push_back(m);
        rec(ind + 1, n, k, xx, mask, p);
        mask.pop_back();
    }
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> xx(k);
    for (auto &i : xx) {
        cin >> i;
        i--;
    }
    vector<ll> p(n);
    for (ll i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    vector<ll> mask;
    rec(0, n, k, xx, mask, p);
    cout << ans % mod << '\n';
}
