//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}


/*
struct E {
    int to, rev, cap;
};
VV<E> g;
auto add_edge = [&](int from, int to, int cap) {
    g[from].push_back(E{to, int(g[to].size()), cap});
    g[to].push_back(E{from, int(g[from].size())-1, 0});
};
*/

template<class C>
struct MaxFlow {
    C flow;
    V<char> dual;  // false: S-side true: T-side
};

template<class C, class E>
struct MFExec {
    static constexpr C INF = numeric_limits<C>::max();
    C eps;
    VV<E>& g;
    int s, t;
    V<int> level, iter;

    C dfs(int v, C f) {
        if (v == t) return f;
        C res = 0;
        for (int& i = iter[v]; i < int(g[v].size()); i++) {
            E& e = g[v][i];
            if (e.cap <= eps || level[v] >= level[e.to]) continue;
            C d = dfs(e.to, min(f, e.cap));
            e.cap -= d;
            g[e.to][e.rev].cap += d;
            res += d;
            f -= d;
            if (f == 0) break;
        }
        return res;
    }

    MaxFlow<C> info;
    MFExec(VV<E>& _g, int _s, int _t, C _eps)
        : eps(_eps), g(_g), s(_s), t(_t) {
        int N = int(g.size());

        C& flow = (info.flow = 0);
        while (true) {
            queue<int> que;
            level = V<int>(N, -1);
            level[s] = 0;
            que.push(s);
            while (!que.empty()) {
                int v = que.front(); que.pop();
                for (E e: g[v]) {
                    if (e.cap <= eps || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
            if (level[t] == -1) break;
            iter = V<int>(N, 0);
            while (true) {
                C f = dfs(s, INF);
                if (!f) break;
                flow += f;
            }
        }
        for (int i = 0; i < N; i++) info.dual.push_back(level[i] == -1);
    }
};

template<class C, class E>
MaxFlow<C> get_mf(VV<E>& g, int s, int t, C eps) {
    return MFExec<C, E>(g, s, t, eps).info;
}

pair<VV<int>, V<int>> cyc(V<int> p) {
    int n = int(p.size());
    VV<int> cys;
    V<int> used(n);
    for (int i = 0; i < n; i++) {
        if (used[i]) continue;
        V<int> cy;
        int st = i;
        while (!used[st]) {
            used[st] = true;
            cy.push_back(st);
            st = p[st];
        }
        if (cy.size() > 1) {
            cys.push_back(cy);
        }
    }
    V<int> id(n, -1);
    int m = int(cys.size());
    for (int i = 0; i < m; i++) {
        for (int j: cys[i]) {
            id[j] = i;
        }
    }
    return {cys, id};
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    V<int> p(n), q(n);

    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }

    auto pinfo = cyc(p);
    auto qinfo = cyc(q);

    dbg(pinfo, qinfo);


    int ln = int(pinfo.first.size());
    int rn = int(qinfo.first.size());
    int sv = ln + rn, tv = sv + 1;
    struct E {
        int to, rev, cap;
    };
    VV<E> g(ln + rn + 2);
    auto add_edge = [&](int from, int to, int cap) {
        g[from].push_back(E{to, int(g[to].size()), cap});
        g[to].push_back(E{from, int(g[from].size())-1, 0});
    };    

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int pid = pinfo.second[i];
        int qid = qinfo.second[i];

        if (pid == -1 && qid == -1) {
            ans++;
            continue;
        }
        if (pid != -1 && qid != -1) {
            add_edge(ln + qid, pid, 1);
            if (p[i] == q[i]) add_edge(pid, ln + qid, 1);
            continue;
        }
        if (pid == -1 && qid != -1) {
            add_edge(ln + qid, tv, 1);
            continue;
        }
        if (pid != -1 && qid == -1) {
            add_edge(sv, pid, 1);
            continue;
        }
    }

    ans += get_mf(g, sv, tv, 0).flow;

    cout << n - ans << endl;
    return 0;
}


Measured memory_bytes: 15252