#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 0x7FFFFFFFFFFFFFFF / 2;
bool func[300001];
vector<int> graph[300001];
int dfs(int i, int N) {
  if (graph[i].empty()) {
    return N;
  }
  vector<int> possible_values;
  for (int c : graph[i]) {
    possible_values.push_back(dfs(c, N));
  }
  int mx = *max_element(possible_values.begin(), possible_values.end());
  if (func[i] == 1) {
    return mx;
  } else {
    int s = 0;
    sort(possible_values.begin(), possible_values.end(), greater<int>());
    for (int i = 0; i < possible_values.size() - 1; i++) {
      s += (N - possible_values[i]);
    }
    return (possible_values.back() - s - (int)graph[i].size() + 1);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, p;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> func[i];
  }
  for (int i = 2; i <= n; i++) {
    cin >> p;
    graph[p].push_back(i);
  }
  int l = 0;
  for (int i = 1; i <= n; i++) {
    if (graph[i].empty()) {
      l++;
    }
  }
  cout << dfs(1, l);
  return 0;
}
