#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6, N2 = 5e3, delta = 46639, mod = 1e9 + 7, oo = 1e16;
const long double PI = 3.141592653589793;
long long int ans = 1;
bool mark[N];
vector<long long int> v[N];
long long int dfs(long long int x) {
  if (v[x].size() == 0) {
    ans++;
    return -1;
  }
  if (mark[x]) {
    long long int mx = -oo;
    for (auto u : v[x]) mx = max(mx, dfs(u));
    return mx;
  }
  long long int mn = 0;
  for (auto u : v[x]) mn += dfs(u);
  return mn;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> mark[i];
  for (long long int i = 0; i < n - 1; i++) {
    long long int x;
    cin >> x;
    x--;
    v[x].push_back(i + 1);
  }
  ans += dfs(0);
  cout << ans;
  return 0;
}
