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

struct Dinic{
    struct edge{
        int to, flow, cap;
    };

    const static int N = 200007; //count of vertices

    vector<edge> e;
    vector<int> g[N + 7];
    int dp[N + 7];
    int ptr[N + 7];

    void clear(){
        for (int i = 0; i < N + 7; i++) g[i].clear();
        e.clear();
    }

    void addEdge(int a, int b, int cap){
    	//cout << a << " " << b << " " << cap << endl;
        g[a].pb(e.size());
        e.pb({b, 0, cap});
        g[b].pb(e.size());
        e.pb({a, 0, 0});
    }

    int minFlow, start, finish;

    bool bfs(){
        for (int i = 0; i < N; i++) dp[i] = -1;
        dp[start] = 0;
        vector<int> st;
        int uk = 0;
        st.pb(start);
        while(uk < st.size()){
            int v = st[uk++];
            for (int to : g[v]){
                auto ed = e[to];
                if (ed.cap - ed.flow >= minFlow && dp[ed.to] == -1){
                    dp[ed.to] = dp[v] + 1;
                    st.pb(ed.to);
                }
            }
        }
        return dp[finish] != -1;
    }

    int dfs(int v, int flow){
        if (v == finish) return flow;
        for (; ptr[v] < g[v].size(); ptr[v]++){
            int to = g[v][ptr[v]];
            edge ed = e[to];
            if (ed.cap - ed.flow >= minFlow && dp[ed.to] == dp[v] + 1){
                int add = dfs(ed.to, min(flow, ed.cap - ed.flow));
                if (add){
                    e[to].flow += add;
                    e[to ^ 1].flow -= add;
                    return add;
                }
            }
        }
        return 0;
    }

    int dinic(int start, int finish){
        Dinic::start = start;
        Dinic::finish = finish;
        int flow = 0;
        for (minFlow = (1 << 30); minFlow; minFlow >>= 1){
            while(bfs()){
                for (int i = 0; i < N; i++) ptr[i] = 0;
                while(int now = dfs(start, (int)2e9 + 7)) flow += now;
            }
        }
        return flow;
    }
} dinic;

signed main()
{
	#ifdef LOCAL
	    freopen("H_input.txt", "r", stdin);
	    //freopen("B_output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int n;
   	cin >> n;
   	vector<int> a(n), b(n);
   	for (int i=0; i < n; ++i) cin >> a[i];
   	for (int i=0; i < n; ++i) cin >> b[i];
   	vector<int> posa(n), posb(n);
   	for (int i=0;i<n;++i) posa[a[i]] = i;
   	for (int i=0; i < n; ++i) posb[b[i]] = i;
   	vector<int> cyclea(n, -1), cycleb(n, -1);
   	int A = 0, B = 0;
   	for (int i=0; i < n; ++i){
   		if (cyclea[i] != -1) continue;
   		int cur = A++;
   		int now = i;
   		bool mv = false;
   		while (!mv || now != i){
   			mv = true;
   			cyclea[now] = cur;
   			now = a[now];
   		}
   	}
   	for (int i=0; i < n; ++i){
   		if (cycleb[i] != -1) continue;
   		int cur = B++;
   		int now = i;
   		bool mv = false;
   		while (!mv || now != i){
   			mv = true;
   			cycleb[now] = cur;
   			now = b[now];
   		}
   	}

   	Dinic d;

   	int ans=0;
   	int tot = A+B+2;
   	for (int i=0;i<n;++i){
   		int E = posa[i], F = posb[i];
   		if (F==E && F==i){
   			ans++;
   			continue;
   		}
   		int ca = cyclea[i], cb = cycleb[i];
   		// /cout << ca << " " << cb << " " << E << " " << F  << endl;
   		if (E==i){
   			d.addEdge(A+1+cb, A+B+1, 1);
   		}
   		else if (F==i){
   			d.addEdge(0, ca+1, 1);
   		}
   		else{
   			if (E==F){
   				d.addEdge(ca+1, A+1+cb, 1);
   				d.addEdge(A+1+cb, ca+1, 1);
   			}
   			else{
   				d.addEdge(A+1+cb, ca+1, 1);
   			}
   		}
   	}
   	ans += d.dinic(0, A+B+1);
   	cout << n-ans;


    return 0;
}

Measured memory_bytes: 24108