#include <bits/stdc++.h>
using namespace std;
int read();

int n, s, t;
int p[200005], q[200005];
int id[2][200005], idcnt;



int hd[200005], nx[1000006], to[1000006], c[1000006], cnt;
void add(int f, int t, int cap) {
    nx[++cnt] = hd[f], hd[f] = cnt, to[cnt] = t, c[cnt] = cap;
}
void fadd(int f, int t, int c) { add(f, t, c), add(t, f, 0); }
struct Flow {
    int dep[200005];
    queue<int> q;
    bool bfs() {
        for (int i = 1; i <= t; ++i) dep[i] = 0;
        dep[s] = 1, q.push(s);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int i = hd[u], v; i; i = nx[i]) {
                if (!c[i] || dep[v = to[i]]) continue;
                dep[v] = dep[u] + 1, q.push(v);
            }
        }
        return dep[t];
    }

    int iter[200005];
    int dfs(int u, int dist) {
        if (u == t) return dist;
        for (int &i = iter[u], v, d; i; i = nx[i]) {
            if (!c[i] || dep[v = to[i]] != dep[u] + 1) continue;
            if (d = dfs(v, min(dist, c[i]))) return c[i] -= d, c[i ^ 1] += d, d;
        }
        return 0;
    }
    int Dinic() {
        int rt = 0, d;
        while (bfs()) {
            for (int i = 1; i <= t; ++i) iter[i] = hd[i];
            while (d = dfs(s, 10000000)) rt += d;
        }
        return rt;
    }
} flow;
void work(int u, int* nx, int* id) {
    if (id[u]) return;
    id[u] = idcnt, work(nx[u], nx, id);
}
int main() {
    n = read(), cnt = 1;
    for (int i = 1; i <= n; ++i) p[i] = read() + 1;
    for (int i = 1; i <= n; ++i) q[i] = read() + 1;
    int res = n;
    for (int i = 1; i <= n; ++i)
        if (!id[0][i]) ++idcnt, work(i, p, id[0]);
    for (int i = 1; i <= n; ++i)
        if (!id[1][i]) ++idcnt, work(i, q, id[1]);

    s = ++idcnt, t = ++idcnt;
    for (int i = 1; i <= n; ++i)
        if (p[i] == i && q[i] == i) --res;
        else if (p[i] == i) fadd(id[1][i], t, 1);
        else if (q[i] == i) fadd(s, id[0][i], 1);
        else if (p[i] != q[i]) fadd(id[1][i], id[0][i], 1);
        else fadd(id[1][i], id[0][i], 1), fadd(id[0][i], id[1][i], 1);
    printf("%d\n", res - flow.Dinic());
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}