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

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")
// #pragma GCC optimize("unroll-loops")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 998244353;

vector<vector<ll>> g;
vector<bool> have;

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(k);
    have.assign(n, false);
    for (ll i = 0; i < k; i++) {
        cin >> a[i];
        have[a[i] - 1] = true;
    }
    g.resize(n);
    bool fl = true;
    for (ll i = 1; i < n; i++) {
        ll x;
        cin >> x;
        if (x != i) {
            fl = false;
        }
        g[x - 1].push_back(i);
    }
    if (fl) {
        ll ans = 1;
        ll cnt = k;
        for (ll i = n - 1; i >= 0; i--) {
            if (!have[i]) {
                ans = (ans * (cnt + 1)) % mod;
            } else {
                cnt--;
            }
        }
        cout << ans;
    }
}

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