#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,M=200005,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,cnt,S,T,ans,a[N],b[N],bela[N],belb[N];
int fir[N],firr[N],siz;
struct edge{int u,v,w,nex;}e[M*2];
void add(int u,int v,int w){
	e[++siz]=(edge){u,v,w,fir[u]};fir[u]=siz;
	e[++siz]=(edge){v,u,0,fir[v]};fir[v]=siz;
}
int dist[N],que[N];
void dec(int x,int fl){e[x].w-=fl;e[x^1].w+=fl;}
bool bfs(int S,int T){
	memset(dist,0x3f,4*(cnt+1));
	int l=1,r=1;que[l]=S;dist[S]=0;
	while (l<=r){
		int x=que[l];
		for (int i=fir[x];i;i=e[i].nex)
		if ((e[i].w)&&(dist[e[i].v]>dist[x]+1)){
			que[++r]=e[i].v;
			dist[e[i].v]=dist[x]+1;
		}
		l++;
	}
	return dist[T]!=inf;
}
int dfs(int x,int flow){
	if (x==T) return flow;
	int fl=0,t=0;
	for (int i=firr[x];i;i=e[i].nex)
	if (e[i].w&&(dist[e[i].v] == dist[x] + 1)){
		t=dfs(e[i].v,min(flow-fl,e[i].w));
		dec(i,t);fl+=t;
		if (fl==flow) {firr[x]=i;return fl;}
	}
	firr[x]=0;
	return fl;
}
int dinic(){
	int flow=0;
	while (bfs(S,T)){
		for (int i=0;i<=cnt;i++) firr[i]=fir[i];
		flow+=dfs(S,inf);
		//cerr<<flow<<endl;
	}
	return flow;
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	siz=1;
	n=read();
	for (int i=1;i<=n;i++) a[i]=read()+1;
	for (int i=1;i<=n;i++) b[i]=read()+1;
	for (int i=1;i<=n;i++)
	if ((a[i]!=i)&&(!bela[i])){
		cnt++;int x=i;
		while (!bela[x]){bela[x]=cnt;x=a[x];}
	}
	for (int i=1;i<=n;i++)
	if ((b[i]!=i)&&(!belb[i])){
		cnt++;int x=i;
		while (!belb[x]){belb[x]=cnt;x=b[x];}
	}
	S=0;T=cnt+1;cnt++;ans=n;
	for (int i=1;i<=n;i++)
	if (bela[i]&&belb[i]) {
		add(bela[i],belb[i],1);
		if (a[i]==b[i]) add(belb[i],bela[i],1);
	}
	else if (bela[i]) add(bela[i],T,1);
	else if (belb[i]) add(S,belb[i],1);
	else ans--;
	ans-=dinic();
	printf("%d\n",ans);
	return 0;
}