#include <bits/stdc++.h>
using namespace std;
int n;
const int MX = 3e5 + 5;
vector<int> ch[MX];
int p[MX];
int a[MX];
int dp[MX];
int b[MX];
int f(int v) {
  int x;
  int k = 0;
  if (a[v]) k = -MX;
  int s = ch[v].size();
  for (auto &u : ch[v]) {
    if (a[v] == 0)
      k += f(u);
    else
      k = max(f(u), k);
    b[v] += b[u];
  }
  if (s == 0) {
    b[v] = 1;
    return 0;
  }
  if (a[v] == 0)
    return k - s + 1;
  else
    return k;
}
int main() {
  cin >> n;
  int i, j;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 2; i <= n; i++) scanf("%d", &p[i]), ch[p[i]].push_back(i);
  printf("%d", f(1) + b[1]);
  return 0;
}
