#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll

using pii = pair<int, int>;

const int MOD = 998244353;
struct modint{
    int val;
    modint(int x){
        if(x >= MOD){
            x %= MOD;
        }
        val = x;
    }
    modint(){
        val = 0;
    }
};

modint operator+(modint a, modint b){
    return a.val + b.val - (a.val + b.val >= MOD ? MOD : 0);
}

modint operator-(modint a, modint b){
    return a.val - b.val + (a.val - b.val < 0 ? MOD : 0);
}

modint operator*(modint a, modint b){
    return ((ll)a.val * b.val) % MOD;
}

modint bpow(modint a, int x){
    if(x == 0){
        return 1;
    }
    modint res = bpow(a, x / 2);
    res = res * res;
    if(x % 2 == 1){
        res = res * a;
    }
    return res;
}

modint inv(modint a){
    return bpow(a, MOD - 2);
}

modint operator/(modint a, modint b){
    return a * inv(b);
}

struct Graph{
    vector<vector<int>> g;
    vector<bool> task;
    vector<int> size;
    vector<int> tin, tout;
    int time = 0;
    Graph(int n): g(n), task(n), size(n), tin(n), tout(n){}

    void add_edge(int v, int u){
        // v -> u 
        g[v].push_back(u);
    }

    void cnt_sz(int v){
        tin[v] = time++;
        size[v] = 1;
        for(auto u : g[v]){
            cnt_sz(u);
            size[v] += size[u];
        }
        tout[v] = time;
    }

    int lca(const vector<int> &a, int v = 0){
        if(a.size() == 1){
            return a.back();
        }
        for(auto u : g[v]){
            bool al = true;
            for(auto x : a){
                if(!in(u, x)){
                    al = false;
                    break;
                }
            }
            if(al){
                return lca(a, u);
            }
        }
        return v;
    }

    bool in(int v, int u){
        return (tin[v] <= tin[u]) && (tout[u] <= tout[v]);
    }
};

void solve(){
    int n, k;
    cin >> n >> k;
    Graph g(n);
    vector<int> tasks(k);
    for(int i = 0; i < k; i++){
        int t;
        cin >> t;  
        tasks[i] = t - 1;
    }
    for(int i = 1; i < n; i++){
        int v;
        cin >> v;
        v--;
        g.add_edge(v, i);
    }
    g.cnt_sz(0);
    vector<vector<modint>> dp(k + 1, vector<modint>(1 << n));
    dp[0][0] = 1;
    modint ans = 0;
    for(int j = 1; j <= k; j++){
        for(int mask = 1; mask < (1 << n); mask++){
            for(int submask = 1; submask <= mask; submask++){
                if((mask & submask) != submask){
                    continue;
                }
                vector<int> tocheck;
                for(int i = 0; i < n; i++){
                    if(!((submask >> i) & 1)){
                        continue;
                    }
                    tocheck.push_back(i);
                }
                if(g.lca(tocheck) == tasks[j - 1]){
                    dp[j][mask] = dp[j][mask] + dp[j - 1][mask ^ submask];
                }
            }
            if(j == k){
                ans = ans + dp[j][mask];
            }
        }
    }
    cout << ans.val << '\n';
}

signed main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}