#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
// #include <iostream>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
typedef long long li;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) { return Pow(x, mod - 2); }
template <class T> inline void Max(T &x, T y) { if (y > x) x = y; }
template <class T> inline void Min(T &x, T y) { if (y < x) x = y; }

// ----------------------------------------

namespace dinic {
  const int maxn = 4e5, maxm = 2e6;
  typedef int FlowType;
  const FlowType inf_f = ~0U >> 1;

  void Init(int n);
  void AddEdge(int u, int v, FlowType cap, int id);
  FlowType Solve(int s, int t);
  vector< pair<int, FlowType> > Result(void);
}

namespace dinic {
  struct Edge {
    int v, id;
    FlowType cap, cap0;
  } edge[maxm << 1];

  int n, m, s, t;
  vector<int> g[maxn];

  void Init(int _n) {
    n = _n, m = 0;
    for (int i = 0; i < n; ++i) g[i].clear();
  }

  void AddEdge(int u, int v, FlowType c, int id = -1) {
    g[u].push_back(m);
    edge[m++] = (Edge){v, id, c, c};
    g[v].push_back(m);
    edge[m++] = (Edge){u, id, 0, 0};
  }

  int iter[maxn], dist[maxn];

  bool Bfs(void) {
    queue<int> que;
    que.push(s);
    FILL(dist, n, -1);
    dist[s] = 0;
    while (!que.empty()) {
      int u = que.front(); que.pop();
      for (int i = 0; i < g[u].size(); ++i) {
        Edge &e = edge[g[u][i]];
        if (e.cap && dist[e.v] == -1) {
          dist[e.v] = dist[u] + 1;
          que.push(e.v);
        }
      }
    }
    return dist[t] >= 0;
  }

  FlowType Dfs(int u, FlowType f) {
    if (u == t) return f;
    FlowType sum = 0;
    for (int &i = iter[u]; i < g[u].size(); ++i) {
      Edge &e = edge[g[u][i]], &rev = edge[g[u][i] ^ 1];
      if (e.cap && dist[e.v] == dist[u] + 1) {
        FlowType res = Dfs(e.v, min(f - sum, e.cap));
        e.cap -= res;
        rev.cap += res;
        if ((sum += res) == f) break;
      }
    }
    return sum;
  }

  FlowType Solve(int _s, int _t) {
    s = _s, t = _t;
    FlowType ans = 0;
    while (Bfs()) {
      FILL(iter, n, 0);
      ans += Dfs(s, inf_f);
    }
    return ans;
  }

  vector< pair<int, FlowType> > Result(void) {
    vector< pair<int, FlowType> > ans;
    for (int u = 0; u < n; ++u) {
      for (int i = 0; i < g[u].size(); ++i) {
        Edge &e = edge[g[u][i]];
        if (e.cap < e.cap0 && e.id != -1) {
          ans.push_back(make_pair(e.id, e.cap0 - e.cap));
        }
      }
    }
    return ans;
  }
}

// ----------------------------------------

const int maxn = 1e5, inf = 1e9;

int n;
int p[maxn], q[maxn];
int A[maxn], B[maxn];

void GetR(int *p, int *A) {
  FILL(A, n, -1);
  for (int i = 0; i < n; ++i) {
    if (A[i] == -1) {
      A[i] = i;
      for (int j = p[i]; j != i; j = p[j]) {
        A[j] = i;
      }
    }
  }
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", p + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", q + i);
  }
  GetR(p, A);
  GetR(q, B);

  int N = 2 * n + 2, S = N - 2, T = N - 1;
  dinic::Init(N);

  int cost = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i] == i && q[i] == i) {
      cost += 1;
    } else if (p[i] == q[i]) {
      dinic::AddEdge(A[i], n + B[i], 1);
      dinic::AddEdge(n + B[i], A[i], 1);
    } else if (i == p[i]) {
      dinic::AddEdge(S, n + B[i], 1);
    } else if (i == q[i]) {
      dinic::AddEdge(A[i], T, 1);
    } else {
      dinic::AddEdge(A[i], n + B[i], 1);
    }
    // dinic::AddEdge(i, p[i], inf);
    // dinic::AddEdge(n + i, n + q[i], inf);
  }

  cost += dinic::Solve(S, T);
  printf("%d\n", n - cost);
  return 0;
}


Measured memory_bytes: 25984