#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1e5 + 1;
const int INF = 1e7;
int n, cnt;
vector<int> adj[MAXN];
int mn[MAXN];
int solve(int pos) {
  if (adj[pos].empty()) {
    cnt++;
    return 1;
  }
  int ret = mn[pos] == 1 ? INF : 0;
  for (auto next : adj[pos]) {
    if (mn[pos])
      ret = min(ret, solve(next));
    else
      ret += solve(next);
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &mn[i]);
  }
  for (int i = 2; i <= n; i++) {
    int u;
    scanf("%d", &u);
    adj[u].push_back(i);
  }
  int t = solve(1);
  printf("%d\n", cnt + 1 - t);
  return 0;
}
