#include <bits/stdc++.h>
using namespace std;
long long inf1 = 1e18;
const int N = 300 * 1000 + 2;
bool ch[N];
vector<int> a[N];
int ans[N];
int k;
void dfs(int no = 0, int prev = -1) {
  if (a[no].size() <= 1 && no != 0) {
    k++;
    ans[no] = 1;
    return;
  }
  if (ch[no])
    ans[no] = 1000000000;
  else
    ans[no] = 0;
  for (auto i : a[no]) {
    if (i != prev) {
      dfs(i, no);
      if (ch[no])
        ans[no] = min(ans[no], ans[i]);
      else
        ans[no] += ans[i];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int par[n];
  for (int i = (0); i < (n); i++) cin >> ch[i];
  for (int i = (0); i < (n - 1); i++) cin >> par[i + 1];
  par[0] = -1;
  for (int i = (0); i < (n - 1); i++) {
    a[i + 1].push_back(par[i + 1] - 1);
    a[par[i + 1] - 1].push_back(i + 1);
  }
  dfs();
  cout << k + 1 - ans[0];
}
