#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << "(" << v.first << " " << v.second << ")";
  return os;
}
template <typename T, typename U = typename T::value_type,
          typename = typename enable_if<!is_same<T, string>::value>::type>
ostream& operator<<(ostream& os, const T& v) {
  os << '[';
  for (const auto& it : v) os << it << " ";
  if (!v.empty()) os << "\b";
  os << "]";
  return os;
}
int N;
vector<int> op;
vector<vector<int>> children;
pair<int, int> solve(int v) {
  if (children[v].empty()) return {1, 1};
  vector<pair<int, int>> p;
  int num_leafs = 0;
  for (int u : children[v]) {
    p.push_back(solve(u));
    num_leafs += p.back().second;
  }
  if (op[v] == 1) {
    int diff = -1e9;
    for (auto pp : p) diff = max(diff, pp.first - pp.second);
    return {num_leafs + diff, num_leafs};
  } else {
    int diff = 1;
    for (auto pp : p) diff += (pp.first - pp.second) - 1;
    return {num_leafs + diff, num_leafs};
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N;
  op.resize(N);
  children.resize(N);
  for (int i = 0; i < (N); i++) cin >> op[i];
  for (int i = 0; i < (N - 1); i++) {
    int p;
    cin >> p;
    children[p - 1].push_back(i + 1);
  }
  cout << solve(0).first << endl;
  return 0;
}
