#include "iostream"
#include "vector"
#include "queue"
#include "array"
#include "algorithm"

using ll = long long;

const int N = 10, K = 10, mod = 119 << 23 | 1;

int add(int a, int b) {
    return a + b - mod * (a + b >= mod);
}

std::array<int, N> p;
std::array<int, K> x;
std::array<std::array<int, 1 << N>, K + 1> dp;

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, k;
    std::cin >> n >> k;
    for(int i = 0; i < k; ++i){
        std::cin >> x[i];
        --x[i];
    }
    p[0] = -1;
    for(int i = 1; i < n; ++i){
        std::cin >> p[i];
        --p[i];
    }
    for(int mask = 0; mask < (1 << n); ++mask){
        std::vector<int> cnt(n);
        for(int i = 0; i < n; ++i){
            if (!(mask >> i & 1)) {
                continue;
            }
            int v = i;
            while (v >= 0) {
                ++cnt[v];
                v = p[v];
            }
        }
        int fnd = -1;
        for(int i = 0; i < n; ++i){
            if(fnd == -1 || cnt[fnd] <= cnt[i]){
                fnd = i;
            }
        }
        if (fnd == x[0]) {
            dp[1][mask] = add(dp[1][mask], 1);
        }
    }
    for (int solved = 2; solved <= k; ++solved) {
        for (int mask_taken = 0; mask_taken < (1 << n); ++mask_taken) {
            for (int mask = mask_taken; mask > 0; mask = (mask - 1) & mask_taken) {
                std::vector<int> cnt(n);
                for(int i = 0; i < n; ++i){
                    if (!(mask >> i & 1)) {
                        continue;
                    }
                    int v = i;
                    while (v >= 0) {
                        ++cnt[v];
                        v = p[v];
                    }
                }
                int fnd = -1;
                for(int i = 0; i < n; ++i){
                    if(fnd == -1 || cnt[fnd] <= cnt[i]){
                        fnd = i;
                    }
                }
                if(fnd == x[solved - 1]){
                    dp[solved][mask_taken] = add(dp[solved][mask_taken], dp[solved - 1][mask_taken ^ mask]);
                }
            }
        }
    }
    int ans = 0;
    for (int mask_taken = 0; mask_taken < (1 << n); ++mask_taken){
        ans = add(ans, dp[k][mask_taken]);
    }
    std::cout << ans << '\n';
    return 0;
}