#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using ll = long long;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve();

void solve1() {
    auto start = clock();
    while (true) {
        auto now = clock();
        if ((now - start) / CLOCKS_PER_SEC > 1) {
            cout << 2;
            return;
        }
    }
}

int32_t main() {
#ifdef LOCAL
    freopen("Input.txt", "r",stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

constexpr int MAXN = 1e6 + 1;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<bool> x(n, false);
    for (int i = 0; i < k; ++i) {
        int cord;
        cin >> cord;
        x[cord - 1] = true;
    }
    for (int i = 0; i < n - 1; ++i) {
        int j;
        cin >> j;
        if (i + 1 != j) {
            exit(-1);
        }
    }
    ll ans = 1, zan = 0;
    for (int i = 0; i < n; ++i) {
        if (x[i]) {
            zan++;
        } else {
            ans *= (zan + 1);
        }
    }
    cout << ans << '\n';
}
