#include <bits/stdc++.h>
using namespace std;

template <class CapType = int>
struct Dinic {
    struct Edge {
        int to, rev;
        CapType cap;
        Edge(int a, CapType b, int c) : to(a), cap(b), rev(c) {}
    };
    vector<vector<Edge>> g;
    vector<int> lev, iter;
    size_t n;

    Dinic() = default;
    Dinic(size_t n) : n(n) {
        g.assign(n, vector<Edge>());
        lev.assign(n, 0);
        iter.assign(n, 0);
    }

    void AddEdge(int u, int v, CapType cap) {
        g[u].emplace_back(v, cap, g[v].size() - 0);
        g[v].emplace_back(u, 0, g[u].size() - 1);
    }

    bool Bfs(int s, int t) {
        fill(lev.begin(), lev.end(), -1);
        lev[s] = 0;
        vector<int> que(1, s);
        for (size_t it = 0; it < que.size(); ++it) {
            int x = que[it];
            for (const Edge &e : g[x]) {
                if (e.cap == 0) continue;
                if (lev[e.to] == -1) {
                    lev[e.to] = lev[x] + 1;
                    que.push_back(e.to);
                }
            }
        }
        return lev[t] != -1;
    }

    CapType Flow(int x, int t, CapType flow) {
        if (x == t) return flow;
        CapType res = 0;
        for (int &it = iter[x]; it < g[x].size(); it++) {
            Edge &e = g[x][it];
            if (e.cap == 0) continue;
            if (lev[e.to] != lev[x] + 1) continue;
            CapType f = Flow(e.to, t, min(e.cap, flow));
            res += f;
            flow -= f;
            e.cap -= f;
            g[e.to][e.rev].cap += f;
            if (!flow) break;
        }
        if (!res) lev[x] = -1;
        return res;
    }

    CapType operator()(int s, int t) {
        constexpr CapType kInf = numeric_limits<CapType>::max();
        CapType res = 0;
        while (Bfs(s, t)) {
            fill(iter.begin(), iter.end(), 0);
            res += Flow(s, t, kInf);
        }
        return res;
    }
};

int main() {
    int n;
    scanf("%d", &n);
    vector<int> p(n), q(n);
    for (int i = 0; i < n; ++i) scanf("%d", &p[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &q[i]);
    vector<bool> used(n);
    vector<int> x(n), y(n);
    int m = 0, k = 0;
    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        int u = i;
        while (!used[u]) {
            used[u] = true;
            x[u] = m;
            u = p[u];
        }
        m++;
    }
    fill(used.begin(), used.end(), false);
    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        int u = i;
        while (!used[u]) {
            used[u] = true;
            y[u] = k;
            u = q[u];
        }
        k++;
    }
    Dinic<int> flow(m + k + 2);
    const int src = m + k, snk = m + k + 1;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] == i && q[i] == i) {
            ans++;
            continue;
        }
        if (p[i] == i) flow.AddEdge(src, y[i] + m, 1);
        else if (q[i] == i) flow.AddEdge(x[i], snk, 1);
        else if (p[i] != q[i]) flow.AddEdge(x[i], y[i] + m, 1);
        else flow.AddEdge(x[i], y[i] + m, 1), flow.AddEdge(y[i] + m, x[i], 1);
    }
    ans += flow(src, snk);
    printf("%d\n", n - ans); 
    return 0;
}


Measured memory_bytes: 11508