#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
const int mod = 998244353;


struct Flow{
    struct edge{
        int u , v , c;
        edge(){};
        edge(int u , int v , int c):u(u) , v(v) , c(c){};
    }e[maxn * 10    ];
    int nEdge = 0;
    vector<int> adj[maxn];
    vector<int> ::iterator it[maxn];
    void add_edge(int u , int v , int c){
        adj[u].pb(nEdge * 2);
        adj[v].pb(nEdge * 2 + 1);
        e[nEdge * 2] = edge(u,v,c);
        e[nEdge * 2 + 1] = edge(v,u,0);
//        cout << u << " " << v << " " << c << endl;
        ++nEdge;
    }
    int lv[maxn] , s , t;
    void BFS(){
        queue<int> q;
        memset(lv,-1,sizeof lv);
        q.push(t);
        lv[t] = 0;
        int u = t;
        while(!q.empty()){
            u = q.front();q.pop();
            for(auto & c : adj[u]){
                if(e[c ^ 1].c > 0 && lv[e[c].v] == -1){
                    q.push(e[c].v);
                    lv[e[c].v] = lv[u] + 1;
                }
            }
            if(lv[s] != -1)return;
        }
    }
    int DFS(int u , int In){
        if(u == t)return In;
        int Out = 0;
        for( ; it[u] != adj[u].end() ; ++it[u]){
            int c = *it[u];
            if(e[c].c != 0 && lv[e[c].v] == lv[u] - 1){
                int w = DFS(e[c].v , min(In , e[c].c));
                In -= w;
                Out += w;
                e[c].c -= w;
                e[c ^ 1].c += w;
            }
            if(In == 0)return Out;
        }
        return Out;
    }
    int MaxFlow(){
        int res = 0;
        while(BFS() , lv[s] != -1){
            for(int i = 0 ; i < maxn ; ++i){
                it[i] = adj[i].begin();
            }
            res += DFS(s,1 << 30);
        }
        return res;
    }
}G;


int n;

int p[maxn],q[maxn];
int a[maxn],b[maxn];
void Go(int p[] , int a[]){
    int nTime = 0;
    for(int i = 0 ; i < n ; ++i){
        ++nTime;
        if(a[i] > 0)continue;
        int tmp = i;
        do{
            tmp = p[tmp];
            a[tmp] = nTime;
        }while(tmp != i);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> p[i];
    }
    for(int i = 0 ; i < n ; ++i){
        cin >> q[i];
    }
    Go(p,a);Go(q,b);
//    for(int i = 0 ; i < n ; ++i)cout << a[i] << " ";cout << endl;
//    for(int i = 0 ; i < n ; ++i)cout << b[i] << " ";cout << endl;
    int res = n;
    G.s = 0;G.t = n + n + 1;
    for(int i = 0 ; i < n ; ++i){
        int a = ::a[i] , b = ::b[i] + n;
        if(i != p[i] && i != q[i]){
            G.add_edge(a,b,1);
            if(p[i] == q[i])G.add_edge(b,a,1);
        }else if(i == p[i] && i == q[i])res--;
        else if(i == p[i]){
            G.add_edge(G.s,b,1);
        }else if(i == q[i]){
            G.add_edge(a,G.t,1);
        }
    }
    cout << res - G.MaxFlow();
}


Measured memory_bytes: 22400