// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define int long long
using ld = long double;
using ll = long long;
using pii = pair<int, int>;

constexpr int mod = 998244353;
int gm(int val) { return ((val % mod) + mod) % mod; }

int n, k;
vector<bool> is_k;
vector<vector<int>> g;
vector<int> par, tin, tout;
vector<int> mask;
int ct = 0;

int bpow(int a, int p) {
  if (p == 0) {
    return 1;
  } else if (p % 2 == 0) {
    int res = bpow(a, p / 2);
    return gm(res * res);
  } else {
    return gm(a * bpow(a, p - 1));
  }
}

void dfs1(int v, int p) {
  tin[v] = ct++;
  par[v] = p;
  for (const auto& u : g[v]) {
    dfs1(u, v);
  }
  tout[v] = ct++;
}

bool is_parent(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }

int lca(int a, int b) {
  if (is_parent(a, b)) return a;
  while (!is_parent(a, b)) a = par[a];
  return a;
}

bool check() {
  for (int v = 0; v < n; ++v) {
    if (!is_k[v]) continue;
    if (mask[v] == 0) return false;
    int l = -1;
    for (int u = 0; u < n; ++u) {
      if ((mask[v] >> u) & 1) {
        if (l == -1) {
          l = u;
        } else {
          l = lca(l, u);
        }
      }
    }
    if (l != v) {
      return false;
    }
  }
  return true;
}

int ans = 0;

void rec(int i) {
  if (i == n) {
    if (check()) {
      ++ans;
    }
    return;
  }
  rec(i + 1);
  int v = i;
  while (v != -1) {
    if (!is_k[v]) {
      v = par[v];
      continue;
    }
    mask[v] += (1 << i);
    rec(i + 1);
    mask[v] -= (1 << i);
    v = par[v];
  }
}

void solve() {
  cin >> n >> k;
  is_k.resize(n);
  g.resize(n);
  par.resize(n, -1);
  mask.resize(n);
  tin.resize(n);
  tout.resize(n);

  for (int i = 0; i < k; ++i) {
    int x;
    cin >> x;
    --x;
    is_k[x] = true;
  }

  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p;
    --p;
    g[p].push_back(i);
  }

  dfs1(0, -1);
  rec(0);
  cout << ans << '\n';
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

#ifdef ROMALOCAL
  freopen("in.txt", "r", stdin);
#endif

  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}