#include <bits/stdc++.h>
using namespace std;
bool Q[300005];
vector<int> V[300005];
char c;
int num = 0;
int DOO(int x) {
  if (V[x].size() == 0) {
    num++;
    return 1;
  }
  if (Q[x]) {
    int minn;
    for (int i = 0; i < V[x].size(); i++) {
      if (i == 0)
        minn = DOO(V[x][i]);
      else
        minn = min(minn, DOO(V[x][i]));
    }
    return minn;
  } else {
    int summ = 0;
    for (int i = 0; i < V[x].size(); i++) {
      summ += DOO(V[x][i]);
    }
    return summ;
  }
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> c;
    if (c == '1') Q[i] = 1;
  }
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    V[x].push_back(i);
  }
  cout << 1 - DOO(1) + num << endl;
}
