#include <bits/stdc++.h>
const int maxN = 2e5 + 10;
int t[maxN];
int main() {
  int n, x = 1, res = -1;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", t + i + 1);
  for (int i = 0, l; i < n; ++i) {
    scanf("%d", &l);
    x ^= l;
  }
  for (int p, i = 1; i <= n; ++i)
    if (t[i] > 0) {
      res++;
      p = i;
      while (t[p] > 0) {
        t[p] = -t[p];
        p = -t[p];
      }
    }
  if (res > 0) res++;
  printf("%d\n", res + x);
}
