#include <bits/stdc++.h>

#define int long long

using ll = long long;
using ld = long double;
using namespace std;
mt19937 rnd(239);

const int mod = 998244353;

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

    int n, m, x, ok4 = 1; cin >> n >> m;
    vector <int> p(n, -1), a(n, 0);
    for (int i = 0; i < m; i++) {
        cin >> x;
        a[--x] = 1;
    }
    for (int i = 1; i < n; i++) {
        cin >> p[i]; p[i]--;
        if (p[i] != i - 1) ok4 = 0;
    }
    if (ok4) {
        vector <int> pref(n);
        pref[0] = a[0];
        for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + a[i];
        int otv = 1;
        for (int i = 0; i < n; i++) {
            if (a[i]) continue;
            otv = (otv * (pref[i] + 1)) % mod;
        }
        cout << otv << "\n";
    }
    return 0;
}
