#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
const ll inf = 1e13;
void solve();

template<typename T, typename T1> T remax(T& x, T1 y) { if (x < y) x = y; return x; }
template<typename T, typename T1> T remin(T& x, T1 y) { if (y < x) x = y; return x; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}
#define int int64_t

const int mod = 998244353;

void solve() {
    int n, k; cin >> n >> k;
    vector<int> a(k);
    for (auto& x : a) cin >> x, --x;
    vector<vector<int>> g(n);
    for (int i = 1; i < n; ++i) {
        int p; cin >> p;
        --p;
        g[p].emplace_back(i);
    }
    int it = k - 1, ans = 1;
    for (int i = n - 1; i >= 0; --i) {
        if (it >= 0 && a[it] == i) {
            it--;
            continue;
        }
        ans = ans * (it + 2) % mod;
    }
    cout << ans;
}
