#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e5 + 1;
int l[NMAX], m[NMAX];
int t[NMAX];
vector<int> adj[NMAX];
int n;
void parcours(int u) {
  if (adj[u].empty()) {
    l[u] = 1;
    m[u] = 1;
  } else {
    int vMax = -1;
    for (int v : adj[u]) {
      parcours(v);
      l[u] += l[v];
      if (t[u]) {
        if (vMax == -1 || (m[vMax] - l[vMax] < m[v] - l[v])) vMax = v;
      } else {
        m[u] += m[v] - 1;
      }
    }
    if (t[u])
      m[u] = l[u] + m[vMax] - l[vMax];
    else
      m[u]++;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  for (int i = 2; i <= n; i++) {
    int f;
    scanf("%d", &f);
    adj[f].push_back(i);
  }
  parcours(1);
  printf("%d\n", m[1]);
}
