#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ld = long double;

const int MOD = 998244353;

vector<vector<int>> g;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> t(k);
    for (auto &el : t) cin >> el;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int x;
        cin >> x;
        g[x - 1].pb(i + 1);
    }
    sort(all(t));
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        int cur = lower_bound(all(t), i) - t.begin() + 1;
        if (lower_bound(all(t), i) != t.end() && *lower_bound(all(t), i) == i) {
            cur = 1;
        }
        ans = (ll) ans * cur % MOD;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}
