#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
queue<int> Q;
int n, s, t, head[N], tot = 1, dis[N], id[2][N], p[N], q[N], idcnt, cur[N];
struct node{int to, nex, val;}a[1000005];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
void add(int x, int y, int z)
{
	a[++ tot].to = y; a[tot].nex = head[x]; a[tot].val = z; head[x] = tot;
	a[++ tot].to = x; a[tot].nex = head[y]; a[tot].val = 0; head[y] = tot;
}
int bfs()
{
	while(!Q.empty()) Q.pop();
	for(int i = 1; i <= t; i ++) dis[i] = 0;
	dis[s] = 1; Q.push(s);
	while(!Q.empty())
	{
		int x = Q.front(); Q.pop();
		for(int i = head[x]; i; i = a[i].nex)
		{
			int y = a[i].to;
			if(!dis[y] && a[i].val)
			{
				dis[y] = dis[x] + 1;
				if(y == t) return 1;
				Q.push(y);
			}
		}
	}
	return 0;
}
int dfs(int x, int want)
{
	if(x == t || !want) return want;
	int f, get = 0;
	for(int &i = cur[x]; i && want; i = a[i].nex)
	{
		int y = a[i].to;
		if(dis[y] == dis[x] + 1 && a[i].val)
		{
			f = dfs(y, min(want, a[i].val));
			if(!f) {dis[y] = 0; continue;}
			a[i].val -= f; a[i ^ 1].val += f;
			want -= f; get += f;
		}
	}
	return get;
}
int dinic()
{
	int mxflow = 0, flow;
	while(bfs())
	{
		for(int i = 1; i <= t; i ++) cur[i] = head[i];
		while(flow = dfs(s, inf)) mxflow += flow;
	}
	return mxflow;
}
void work(int x, int *nx, int *id) {if(id[x]) return; id[x] = idcnt; work(nx[x], nx, id);}
int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i ++) p[i] = read() + 1;
	for(int i = 1; i <= n; i ++) q[i] = read() + 1;
	int res = n;
	for(int i = 1; i <= n; i ++) if(!id[0][i]) idcnt ++, work(i, p, id[0]);
	for(int i = 1; i <= n; i ++) if(!id[1][i]) idcnt ++, work(i, q, id[1]);
	s = ++ idcnt; t = ++ idcnt;
	for(int i = 1; i <= n; i ++)
	{
		if(p[i] == i && q[i] == i) res --;
		else if(p[i] == i) add(id[1][i], t, 1);
		else if(q[i] == i) add(s, id[0][i], 1);
		else if(p[i] != q[i]) add(id[1][i], id[0][i], 1);
		else add(id[1][i], id[0][i], 1), add(id[0][i], id[1][i], 1);
	}
	printf("%d\n", res - dinic());
	fclose(stdin);
	fclose(stdout);
	return 0;
}
