//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
// gp_hash_table<int, int>table;
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
//find_by_order(x) - итератор на k по величине элемент
//order_of_key(x) - колво элементов в множестве строго меньших чем наш элемент
vector<vector<ll> > graph;

struct segment_tree {
    segment_tree(ll lb, ll rb) : lb(lb), rb(rb), pos(lb) {
        if (lb != rb) {
            ll mid = (lb + rb) / 2;
            l = new segment_tree(lb, mid);
            r = new segment_tree(mid + 1, rb);
        }
    }

    void set(ll ps, ll x) {
        if (lb == rb) {
            mn = x;
            return;
        }
        ll mid = (lb + rb) / 2;
        if (ps <= mid) {
            l->set(ps, x);
        } else {
            r->set(ps, x);
        }
        if (l->mn <= r->mn) {
            mn = l->mn;
            pos = l->pos;
        } else {
            mn = r->mn;
            pos = r->pos;
        }
    }

    ll mn = LLONG_MAX, pos = -1;
    ll lb, rb;
    segment_tree *l = nullptr, *r = nullptr;
};

const ll MOD = 998244353;
ll binpow(ll a, ll n) {
    if (n == 0) {
        return 1;
    }
    if (n == 1) {
        return a % MOD;
    }
    ll g = binpow(a, n / 2);
    if (n % 2 == 0) {
        return (g * g) % MOD;
    }
    return (((g * g) % MOD) * a) % MOD;
}

vector<ll> sz;

void dfs(ll v) {
    sz[v] = 1;
    for (auto u: graph[v]) {
        dfs(u);
        sz[v] += sz[u];
    }
}

void solve() {
    ll n, k;
    cin >> n >> k;
    sz.resize(n);
    vector<ll> x(n);
    graph.resize(n);
    for (ll i = 0; i < n; ++i) {
        cin >> x[i];
        --x[i];
    }
    for (ll i = 1; i < n; ++i) {
        ll p;
        cin >> p;
        graph[p - 1].push_back(i);
    }
    dfs(0);
    ll size = sz[x[0]];
    ll ans = binpow(2ll, size);
    for (auto i: graph[x[0]]) {
        ans -= binpow(2, sz[i]);
        ans += MOD;
        ans %= MOD;
    }
    cout << ans;
}

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