#include<iostream>
#include<cstdio>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP1(u) for(int i=hd[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
#define REP2(u) for(int&i=cr[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
using namespace std;
const int N=200200,M=N<<1,INF=1000010000;
int n,m,S,T,u,fl=1,ans;
int a[N],b[N],c[N],d[N],hd[N],cr[N],dep[N];
queue<int>q;
struct edge{int n,v,c;}e[M];
void add(int u,int v,int c){e[++fl]=(edge){hd[u],v,c};hd[u]=fl;}
void adde(int u,int v,int c){add(u,v,c),add(v,u,0);}
bool bfs(){
	FOR(i,1,T) dep[i]=-1,cr[i]=hd[i];
	dep[S]=0;q.push(S);
	while(q.size()){
		int u=q.front();q.pop();
		REP1(u)if(c && dep[v]<0)
			dep[v]=dep[u]+1,q.push(v);
	}
	return dep[T]>0;
}
int dfs(int u,int E){
	if(u==T) return E;
	int F=0;
	REP2(u)if(c && dep[v]==dep[u]+1){
		int t=dfs(v,min(E,c));
		F+=t,e[i^1].c+=t;
		E-=t,e[i^0].c-=t;
		if(!E) break;
	}
	return F;
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d",&a[i]),a[i]++;
	FOR(i,1,n) scanf("%d",&b[i]),b[i]++;
	S=m=1;
	FOR(i,1,n)if(!c[i]){
		c[u=i]=++m;
		while(u=a[u],u!=i) c[u]=m;
	}
	FOR(i,1,n)if(!d[i]){
		d[u=i]=++m;
		while(u=b[u],u!=i) d[u]=m;
	}
	T=m+1;
	FOR(i,1,n){
		if(a[i]==b[i]){
			if(a[i]==i) ans++;
			else adde(d[i],c[i],1),adde(c[i],d[i],1);
		}
		else{
				 if(b[i]==i) adde(S,c[i],1);
			else if(a[i]==i) adde(d[i],T,1);
			else adde(d[i],c[i],1);
		}
	}
	while(bfs()) ans+=dfs(S,INF);
	cout<<n-ans<<'\n';
}