#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int ata[200009];
int tap(int x) {
  if (ata[x] == x) return x;
  return ata[x] = tap(ata[x]);
}
bool merge(int x, int y) {
  if ((x = tap(x)) == (y = (tap(y)))) return 0;
  ata[y] = x;
  return true;
}
int main() {
  int n, x, ans = 0, res = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) ata[i] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &x), ans += merge(i, x);
  for (int i = 1; i <= n; i++) scanf("%d", &x), res = (res xor x);
  ans = (n - 1 - ans);
  if (ans) ans++;
  printf("%d\n", ans + res);
  return 0;
}
