/*
	  Author : @evenbao
	  Created : 2020 / 07 / 12
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second

const int N = 4e5 + 10;
const int INF = 2e9;

struct Edge {
		int to , w , nxt;
} E[N << 2];

int n , tot , m , S , T , cnta , cntb;
int head[N] , level[N] , ca[N] , cb[N] , a[N] , b[N] , cur[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v , int w) {
		E[++tot] = (Edge) {v , w , head[u]}; head[u] = tot;
		E[++tot] = (Edge) {u , 0 , head[v]}; head[v] = tot;
}
inline bool bfs(int s) {
		queue < int > q;
		while (!q.empty()) q.pop();
		for (int i = 1; i <= m; ++i) 
				level[i] = -1;
		level[s] = 0; q.push(s);
		while (q.size()) {
				int u = q.front(); q.pop();
				for (int i = head[u]; i; i = E[i].nxt) {
						int v = E[i].to , w = E[i].w;
						if (w > 0 && level[v] == -1) {
								level[v] = level[u] + 1;
								q.push(v);
								if (v == T) return true;
						}
				}
		}
		return false;
}
inline int dfs(int u , int flow) {
		int rest = flow;
		if (u == T)
				return flow;
		for (int &i = cur[u]; i && rest; i = E[i].nxt) {
				int v = E[i].to , 
						w = E[i].w;
				if (w > 0 && level[v] == level[u] + 1) {
						int arg = dfs(v , min(rest , w));
						E[i].w -= arg; E[i ^ 1].w += arg;
						rest -= arg;
						if (!arg) level[v] = -1;
						continue;
				} 
		}
		return flow - rest;
}
inline int dinic(int s , int t) {
		int ret = 0; S = s , T = t;
		while (bfs(S)) {
				for (int i = 1; i <= m; ++i) cur[i] = head[i];
				ret += dfs(S , INF);
		}
		return ret;
}
int main() {
		
		read(n);
		for (int i = 1; i <= n; ++i) read(a[i]) , ++a[i];
		for (int i = 1; i <= n; ++i) read(b[i]) , ++b[i];
		for (int i = 1; i <= n; ++i) {
				if (!ca[i]) {
						int now = i; ++cnta;
						while (!ca[now]) ca[now] = cnta , now = a[now];
				}
		}
		for (int i = 1; i <= n; ++i) {
				if (!cb[i]) {
						int now = i; ++cntb;
						while (!cb[now]) cb[now] = cntb , now = b[now];
				}
		}
		int answer = n; tot = 1;
		for (int i = 1; i <= n; ++i) {
				if (a[i] == i && b[i] == i) --answer;
				else if (a[i] == i) AddEdge(1 , cnta + 2 + cb[i] , 1);
				else if (b[i] == i) AddEdge(ca[i] + 2 , 2 , 1);
				else {
						AddEdge(ca[i] + 2 , cnta + 2 + cb[i] , 1);
						if (a[i] == b[i]) AddEdge(cb[i] + cnta + 2 , ca[i] + 2 , 1);
				}
		}
		m = cnta + cntb + 2; 
		answer -= dinic(1 , 2);
		printf("%d\n" , answer);
	  return 0;
}

