#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, cnt = 0, op[N], dp[N];
vector<int> G[N];
void dfs(int u) {
  if (G[u].size() == 0) {
    dp[u] = 1;
    cnt++;
    return;
  }
  if (op[u]) {
    for (auto v : G[u]) {
      dfs(v);
      dp[u] = min(dp[v], dp[u]);
    }
  } else {
    dp[u] = 0;
    for (auto v : G[u]) {
      dfs(v);
      dp[u] += dp[v];
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = (1); i < (n + 1); i++) {
    cin >> op[i];
  }
  memset(dp, 0x7f, sizeof(dp));
  for (int i = (2); i < (n + 1); i++) {
    int f;
    cin >> f;
    G[f].push_back(i);
  }
  dfs(1);
  cout << cnt + 1 - dp[1];
  return 0;
}
