#include <bits/stdc++.h>
using namespace std;
int n;
int A[300003];
vector<int> vec[300002];
int dp[300003];
int sz[300003];
void dfs(int u) {
  for (int v : vec[u]) {
    dfs(v);
    sz[u] += sz[v];
  }
  if (!vec[u].size()) {
    sz[u] = 1;
    dp[u] = 1;
  } else if (A[u] == 1) {
    for (int v : vec[u]) {
      dp[u] = max(dp[u], sz[u] - (sz[v] - dp[v]));
    }
  } else {
    dp[u] = 1;
    for (int v : vec[u]) dp[u] += (dp[v] - 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    vec[p].push_back(i);
  }
  dfs(1);
  printf("%d\n", dp[1]);
}
