#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define N 200010
const int inf=0x3f3f3f3f;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],b[N],head[N],cnt,ia[N],ib[N],tot,S,T,dep[N],pre[N];
struct Edge{
	int to,nxt,val;
}edge[N<<2];
void Add(int a,int b,int c){
	edge[++cnt]={b,head[a],c};
	head[a]=cnt;
}
void adde(int a,int b,int c){
	Add(a,b,c),Add(b,a,0);
}
queue<int> q;
bool bfs(){
	memset(dep,0,sizeof(dep));
	dep[S]=1;
	q.push(S);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(edge[i].val&&!dep[v]){
				dep[v]=dep[u]+1;
				q.push(v);
			}
		}
	}
	return dep[T]>0;
}
int dfs(int u,int limit){
	if(u==T)return limit;
	int flow=0;
	for(int &i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(edge[i].val&&dep[v]==dep[u]+1){
			int k=dfs(v,min(limit,edge[i].val));
			edge[i].val-=k;
			edge[i^1].val+=k;
			flow+=k;
			limit-=k;
		}
		if(!limit)break;
	}
	if(!flow)dep[u]=inf;
	return flow;
}
int Dinic(){
	int maxflow=0;
	for(int i=1;i<=tot;++i){
		pre[i]=head[i];
	}
	while(bfs()){
		maxflow+=dfs(S,inf);
		for(int i=1;i<=tot;++i){
			head[i]=pre[i];
		}
	}
	return maxflow;
}
int main(){
	n=read(),cnt=1,S=++tot,T=++tot;
	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(ia[i])continue;
		int u=i;
		++tot;
		while(!ia[u]){
		   ia[u]=tot;
		   u=a[u];
		}
	}
	for(int i=1;i<=n;++i){
		if(ib[i])continue;
		int u=i;
		++tot;
		while(!ib[u]){
		   ib[u]=tot;
		   u=b[u];
		}
	}
	int same=0;
	for(int i=1;i<=n;++i){
		if(a[i]==i&&b[i]==i){
			++same;
		}
		else if(a[i]==i){
			adde(ib[i],T,1);
		}
		else if(b[i]==i){
			adde(S,ia[i],1);
		}
		else{
			adde(ib[i],ia[i],1);
			if(a[i]==b[i])adde(ia[i],ib[i],1);
		}
	}
	same+=Dinic();
	printf("%d\n",n-same);
	return 0;
}

