#include <bits/stdc++.h>
using namespace std;
enum Operation : unsigned int { OPERATION_MIN, OPERATION_MAX };
struct Node {
  Node *parent;
  unsigned int valuableNumbers;
  Operation operation;
};
int main() {
  unsigned int n, k(0);
  scanf("%u", &n);
  Node *nodes((Node *)malloc(sizeof(Node) * n));
  for (Node *node(nodes), *end(nodes + n); node < end; ++node) {
    scanf("%u", &node->operation);
    node->valuableNumbers = 0;
  }
  for (Node *node(nodes + 1), *end(nodes + n); node < end; ++node) {
    unsigned int j;
    scanf("%u", &j);
    node->parent = nodes + j - 1;
  }
  for (Node *node(nodes + n - 1); node > nodes; --node) {
    if (node->valuableNumbers == 0) {
      ++k;
      node->valuableNumbers = 1;
    }
    if (node->parent->valuableNumbers == 0) {
      node->parent->valuableNumbers = node->valuableNumbers;
    } else if (node->parent->operation == OPERATION_MAX) {
      if (node->valuableNumbers < node->parent->valuableNumbers) {
        node->parent->valuableNumbers = node->valuableNumbers;
      }
    } else {
      node->parent->valuableNumbers += node->valuableNumbers;
    }
  }
  printf("%u", k + 1 - nodes->valuableNumbers);
  free(nodes);
  return 0;
}
