/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 200010;
const int MAXM = 400010;
const int inf = 1919810;

int tot = 1;
int to[MAXM];
int ne[MAXM];
int fl[MAXM];
int fi[MAXN];

inline void Link(int u, int v, int w) {
	tot++;
	to[tot] = v;
	fl[tot] = w;
	ne[tot] = fi[u];
	fi[u] = tot;
}

inline void AddEdge(int u, int v, int w) {
	Link(u, v, w), Link(v, u, 0);
}

int dis[MAXN];
int cur[MAXN];

inline int BFS(int S, int T) {
	memset(dis, 0, sizeof(dis));
	memcpy(cur, fi, sizeof(fi));
	queue<int>q; q.push(S), dis[S] = 1;
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i = fi[x]; i; i = ne[i]) {
			int u = to[i];
			if(!dis[u] && fl[i]) {
				dis[u] = dis[x] + 1;
				q.push(u);
			}
		}
	} return dis[T];
}

inline int DFS(int x, int T, int mx) {
	if(x == T) return mx;
	int flow = 0;
	for(int &i = cur[x]; i; i = ne[i]) {
		int u = to[i];
		if(dis[u] == dis[x] + 1 && fl[i]) {
			int k = DFS(u, T, min(fl[i], mx - flow));
			fl[i] -= k, fl[i ^ 1] += k, flow += k;
			if(flow == mx) return flow;
		}
	} return flow;
}

inline int Dinic(int S, int T) {
	int Flow = 0;
	while(BFS(S, T)) Flow += DFS(S, T, inf);
	return Flow;
}

int A[MAXN];
int B[MAXN];
int X[MAXN];
int Y[MAXN];
int s[MAXN];
int t[MAXN];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri, S = MAXN - 1, T = MAXN - 2;
	for(int i = 1; i <= n; i++) A[i] = ri + 1;
	for(int i = 1; i <= n; i++) B[i] = ri + 1;
	int N = 0, M = 0;
	for(int i = 1; i <= n; i++) {
		if(!X[i]) {
			int p = i; ++N;
			while(!X[p]) X[p] = N, p = A[p];
		}
		if(!Y[i]) {
			int p = i; ++M;
			while(!Y[p]) Y[p] = M, p = B[p];
		}
	}
	int res = n;
	for(int i = 1; i <= n; i++) {
		if(A[i] == i && B[i] == i) --res;
		else if(A[i] == i) s[Y[i]]++;
		else if(B[i] == i) t[X[i]]++;
		else if(A[i] != B[i]) AddEdge(X[i], Y[i] + N, 1);
		else Link(X[i], Y[i] + N, 1), Link(Y[i] + N, X[i], 1);
	}
	for(int i = 1; i <= M; i++) if(s[i]) AddEdge(S, i + N, s[i]);
	for(int i = 1; i <= N; i++) if(t[i]) AddEdge(i, T, t[i]);
	printf("%d\n", res - Dinic(S, T));
	return 0;
}

Measured memory_bytes: 11136