#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long Hashimoto = 0;
  bool Kanna = 1;
  char I_Love = getchar();
  while (I_Love < '0' || I_Love > '9') {
    if (I_Love == '-') Kanna = 0;
    I_Love = getchar();
  }
  while (I_Love >= '0' && I_Love <= '9') {
    Hashimoto = Hashimoto * 10 + I_Love - '0';
    I_Love = getchar();
  }
  return (Kanna ? Hashimoto : -Hashimoto);
}
template <typename T1, typename T2>
inline void Umax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void Umin(T1 &a, T2 b) {
  if (a > b) a = b;
}
int n;
int a[333333];
vector<int> son[333333];
int k = 0;
int sz[333333];
int dp[333333];
int dfs(int x) {
  if (son[x].size() == 0) return dp[x] = 1;
  for (int i = 0; i < (son[x].size()); ++i) dfs(son[x][i]);
  if (a[x]) {
    for (int i = 0; i < (son[x].size()); ++i) {
      dp[x] = max(dp[x], sz[x] - (sz[son[x][i]] - dp[son[x][i]]));
    }
  } else {
    dp[x] = 1;
    for (int i = 0; i < (son[x].size()); ++i) {
      dp[x] += dp[son[x][i]] - 1;
    }
  }
  return dp[x];
}
void build(int x) {
  if (son[x].size() == 0) sz[x] = 1;
  for (int i = 0; i < (son[x].size()); ++i) {
    build(son[x][i]);
    sz[x] += sz[son[x][i]];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(dp, -1, sizeof(dp));
  n = read();
  for (int i = 0; i < (n); ++i) {
    a[i] = read();
  }
  for (int i = 1; i < (n); ++i) {
    int x = read() - 1;
    son[x].push_back(i);
  }
  for (int i = 0; i < (n); ++i)
    if (son[i].size() == 0) k++;
  build(0);
  cout << dfs(0) << endl;
  return 0;
}
