#include <bits/stdc++.h>
using namespace std;
const int prime = 999983;
const int INF = 0x7FFFFFFF;
const long long INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const long long mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long s = 1;
  while (b > 0) {
    if (b & 1) s = s * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return s;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
const int maxn = 3e5 + 10;
int ans[maxn];
int _max[maxn];
int siz[maxn];
vector<int> G[maxn];
void dfs(int node) {
  if (G[node].size() == 0) {
    siz[node] = 1;
    ans[node] = 1;
    return;
  }
  for (auto c : G[node]) {
    dfs(c);
    siz[node] += siz[c];
  }
  if (_max[node])
    ans[node] = 1;
  else
    ans[node] = INF;
  if (_max[node]) {
    for (auto c : G[node]) {
      if (_max[node]) {
        ans[node] = max(ans[node], siz[node] - (siz[c] - ans[c]));
      }
    }
  } else {
    ans[node] = siz[node];
    for (auto c : G[node]) {
      ans[node] = ans[node] - (siz[c] - ans[c] + 1);
    }
    ans[node] += 1;
  }
}
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", &_max[i]);
  for (int i = 2; i <= n; ++i) {
    int u;
    scanf("%d", &u);
    G[u].push_back(i);
  }
  dfs(1);
  cout << ans[1] << endl;
  return 0;
}
