#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimise("O3, unroll-loops")
#pragma GCC target("avx,avx2,popcnt")

#define int long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define db long double
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvi vector<vi>

const int N = 1e5;
const int K = 20;
const int INF = 1e9;
const int mod = 998244353;
constexpr char nl = '\n';

// lando norris 2025 world champion

int bin_pow(int a, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    __int128 res = 1;
    int pw = a;
    while (p) {
        if (p & 1) {
            res = res * pw % mod;
        }
        pw = pw * pw % mod;
        p >>= 1;
    }
    res %= mod;
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vvi can(n);
    vi task(k);
    vi p(n);
    for (int i = 0; i < k; ++i) cin >> task[i];
    for (int i = 1; i < n; ++i) cin >> p[i];
    if (k == 1) {
        for (int i = 0; i < n; ++i) {
            can[i] = {i};
        }
        for (int i = n - 1; i > 0; --i) {
            p[i]--;
            vi tmp = {};
            merge(all(can[i]), all(tmp), back_inserter(can[p[i]]));
        }
        int c = can[task[0] - 1].size() - 1;
        if (c == 0) {
            cout << 1;
        } else {
            cout << (bin_pow(2, c) + 1) % mod << nl;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
