#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

template <class Flow>
class MaxFlow {
    public:
    
    MaxFlow(int n, Flow eps = 0, Flow inf = 1e9) : size(n), graph(n), EPS(eps), INF(inf) {
        level = (int *)malloc(sizeof(int) * size);
        iter = (int *)malloc(sizeof(int) * size);
        que = (int *)malloc(sizeof(int) * size);
    }
    
    ~MaxFlow() {
        free(level);
        free(iter);
        free(que);
    }
    
    void add_edge(int from, int to, Flow cap) {
        graph[from].push_back(Edge(to, cap, graph[to].size()));
        graph[to].push_back(Edge(from, 0, graph[from].size() - 1));
    }
    
    void add_undirected_edge(int from, int to, Flow cap) {
        graph[from].push_back(Edge(to, cap, graph[to].size()));
        graph[to].push_back(Edge(from, cap, graph[from].size() - 1));
    }
    
    Flow max_flow(int source, int sink) {
        Flow flow = 0;
        
        while (1) {
            bfs(source, sink);
            
            if (level[sink] == -1) return flow;
            
            for (int i = 0; i < size; i++) iter[i] = 0;
            
            flow += dfs(source, sink, INF);
        }
    }
    
    private:
    
    int size;
    Flow EPS;
    Flow INF;
    int *level;
    int *iter;
    int *que;
    
    struct Edge {
        int to;
        Flow cap;
        int rev;
        Edge(int to, Flow cap, int rev) : to(to), cap(cap), rev(rev) {}
    };
    
    vector <vector <Edge> > graph;
    
    void bfs(int from, int to) {
        int qs = 0, qt = 0;
        
        for (int i = 0; i < size; i++) level[i] = -1;
        
        level[from] = 0;
        que[qt++] = from;
        
        while (qs < qt && level[to] == -1) {
            int now = que[qs++];
            
            for (int i = 0; i < graph[now].size(); i++) {
                int next = graph[now][i].to;
                
                if (graph[now][i].cap > EPS && level[next] == -1) {
                    level[next] = level[now] + 1;
                    que[qt++] = next;
                }
            }
        }
    }
    
    Flow dfs(int from, int to, Flow cap) {
        Flow flow = 0;
        
        if (from == to || cap <= EPS) return cap;
        
        for (int &i = iter[to]; i < graph[to].size(); i++) {
            int next = graph[to][i].to;
            Edge &edge = graph[next][graph[to][i].rev];
            Flow res;
            
            if (edge.cap <= EPS || level[next] >= level[to]) continue;
            
            res = dfs(from, next, min(cap - flow, edge.cap));
            
            if (res <= EPS) continue;
            
            edge.cap -= res;
            graph[to][i].cap += res;
            flow += res;
            
            if (abs(flow - cap) <= EPS) break;
        }
        
        return flow;
    }
};

int p[100000];
int q[100000];
int ap[100000];
int aq[100000];
int bp[100000];
int bq[100000];
int fp[100000];
int fq[100000];

int main () {
    int n, cp = 0, cq = 0, s, t, ans = 0, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &p[i]);
    for (i = 0; i < n; i++) scanf("%d", &q[i]);
    
    for (i = 0; i < n; i++) {
        int x = i;
        
        if (fp[x] == 1) continue;
        
        while (fp[x] == 0) {
            fp[x] = 1;
            ap[x] = cp;
            bp[cp]++;
            x = p[x];
        }
        
        cp++;
    }
    
    for (i = 0; i < n; i++) {
        int x = i;
        
        if (fq[x] == 1) continue;
        
        while (fq[x] == 0) {
            fq[x] = 1;
            aq[x] = cq;
            bq[cq]++;
            x = q[x];
        }
        
        cq++;
    }
    
    s = cp + cq;
    t = s + 1;
    MaxFlow <int> mf(cp + cq + 2);
    
    for (i = 0; i < n; i++) {
        int xp = ap[i], xq = aq[i];
        
        if (bp[xp] == 1 && bq[xq] == 1) {
            ans++;
        } else if (bp[xp] == 1) {
            mf.add_edge(cp + xq, t, 1);
        } else if (bq[xq] == 1) {
            mf.add_edge(s, xp, 1);
        } else {
            mf.add_edge(cp + xq, xp, 1);
            if (p[i] == q[i]) mf.add_edge(xp, cp + xq, 1);
        }
    }
    
    ans += mf.max_flow(s, t);
    
    printf("%d\n", n - ans);
    
    return 0;
}


Measured memory_bytes: 12672