#include <bits/stdc++.h>
using namespace std;
int n;
int ops[300005];
int p[300005];
vector<int> v[300005];
int val[300005];
vector<int> temp;
void dfs(int x) {
  for (vector<int>::iterator it = v[x].begin(); it != v[x].end(); it++) {
    dfs(*it);
  }
  temp.clear();
  for (vector<int>::iterator it = v[x].begin(); it != v[x].end(); it++) {
    temp.push_back(val[*it]);
  }
  if (temp.empty()) {
    val[x] = 0;
    return;
  }
  if (ops[x] == 1) {
    sort(temp.begin(), temp.end());
    val[x] = temp[temp.size() - 1];
  } else {
    for (vector<int>::iterator it = temp.begin(); it != temp.end(); it++) {
      val[x] += *it;
    }
    val[x] -= (v[x].size() - 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ops[i]);
  }
  p[0] = -1;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &p[i + 1]);
    p[i + 1]--;
    v[p[i + 1]].push_back(i + 1);
  }
  dfs(0);
  int leaves = 0;
  for (int i = 0; i < n; i++) {
    if (v[i].size() == 0) {
      leaves++;
    }
  }
  printf("%d\n", leaves + val[0]);
}
