#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = 1e6 + 7, mod = 1000000007, M = 2e9;
const long long MAX = 5e18;
int n, u, mx[N], lef[N], ans, child[N], v;
vector<int> g[N];
int dfs(int u = 1, int p = 0) {
  if (lef[u]) return 1;
  int ret = M * mx[u];
  for (int i : g[u]) {
    if (i != p) {
      if (mx[u])
        ret = min(ret, dfs(i, u));
      else
        ret += dfs(i, u);
    }
  }
  return ret;
}
int cnt(int u = 1, int p = 0) {
  for (int i : g[u]) {
    if (i != p) child[u] += cnt(i, u);
  }
  if (!child[u]) child[u]++, lef[u] = 1;
  return child[u];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> mx[i];
  for (int i = 2; i <= n; i++) {
    cin >> u;
    g[i].push_back(u);
    g[u].push_back(i);
  }
  cout << cnt() - dfs() + 1;
  return 0;
}
