#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}
using Tree = vector<vector<int>>;
int n, leaf = 0;
vector<int> ope(300010, 1), dp(300010);
Tree tr(300010);
int rec(int cur) {
  if (tr[cur].size() == 0) return 0;
  if (ope[cur]) {
    dp[cur] = INF;
    for (const auto &ch : tr[cur]) {
      dp[cur] = min(dp[cur], rec(ch));
    }
  } else {
    dp[cur] = -1;
    for (const auto &ch : tr[cur]) {
      dp[cur] += rec(ch) + 1;
    }
  }
  return dp[cur];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ope[i];
  for (int i = 1; i < n; i++) {
    int par;
    cin >> par;
    par--;
    tr[par].push_back(i);
  }
  for (int i = 0; i < n; i++)
    if (static_cast<int>(tr[i].size()) == 0) leaf++;
  cout << leaf - rec(0) << endl;
}
