#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int head[N * 2], to[N * 4], cap[N * 4], nxt[N * 4], eid;
void init_edge() {
	memset(head, -1, sizeof(head));
	eid = 0;
}
void _add_edge(int u, int v, int w) {
	to[eid] = v;
	cap[eid] = w;
	nxt[eid] = head[u];
	head[u] = eid++;
}
void add_edge(int u, int v, int w) {
	_add_edge(u, v, w);
	_add_edge(v, u, 0);
}
int que[N * 2], ql, qr, lvl[N * 2];
bool bfs(int s, int t) {
	ql = 1, qr = 0;
	memset(lvl, -1, sizeof(lvl));
	que[++qr] = s;
	lvl[s] = 0;
	while (ql <= qr) {
		int u = que[ql++];
		for (int i = head[u]; ~i; i = nxt[i]) {
			int v = to[i];
			if (cap[i] > 0 && lvl[v] == -1) {
				lvl[v] = lvl[u] + 1;
				que[++qr] = v;
			}
		}
	}
	return lvl[t] != -1;
}
int vis[N * 2];
int dfs(int u, int t, int fl) {
	if (u == t) return fl;
	int res = 0;
	for (int &i = vis[u]; ~i; i = nxt[i]) {
		int v = to[i];
		if (lvl[v] == lvl[u] + 1 && cap[i] > 0) {
			int tmp = dfs(v, t, min(fl, cap[i]));
			cap[i] -= tmp;
			cap[i ^ 1] += tmp;
			fl -= tmp;
			res += tmp;
			if (!fl) break;
		}
	}
	if (!res) lvl[u] = -1;
	return res;
}
int Dinic(int s, int t) {
	int res = 0;
	while (bfs(s, t)) {
		memcpy(vis, head, sizeof(head));
		res += dfs(s, t, 0x3f3f3f3f);
	}
	return res;
}
int n, a[N], b[N], x[N], y[N];
int tot;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	memset(x, -1, sizeof(x));
	memset(y, -1, sizeof(y));
	for (int i = 0; i < n; i++) if (x[i] == -1) {
		int p = i;
		while (x[p] == -1) {
			x[p] = tot;
			p = a[p];
		}
		tot++;
	}
	for (int i = 0; i < n; i++) if (y[i] == -1) {
		int p = i;
		while (y[p] == -1) {
			y[p] = tot;
			p = b[p];
		}
		tot++;
	}
	int s = tot, t = tot + 1;
	int ans = 0;
	for (int i = 0; i < n; i++) if (a[i] != b[i]) ans++;
	init_edge();
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			if (a[i] == i) continue;
			ans++;
			add_edge(x[i], y[i], 1);
			add_edge(y[i], x[i], 1);
		} else {
			if (a[i] == i) add_edge(s, y[i], 1);
			else if (b[i] == i) add_edge(x[i], t, 1);
			else add_edge(x[i], y[i], 1);
		}
	}
	printf("%d\n", ans - Dinic(s, t));
	return 0;
}