/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-25 10:09:00
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#include<map>
namespace run
{
	const int N=1000010,inf=12345678;
	int n,begin[N],next[N],to[N],e,w[N],ans,id[N],Id[N],m,d[N],q[N],l,r,cur[N],S,T;
	int a[N],b[N];
#define pii std::pair<int,int>
	std::map<pii,int> E;
	void add(int u,int v,int W)
	{
		if(E.count(pii(u,v))){ w[E[pii(u,v)]]+=W; return ; }
		E[pii(u,v)]=++e; next[e]=begin[u]; begin[u]=e; to[e]=v; w[e]=W;
	}
#define fo(i,a) for(int &i=cur[a];i;i=next[i])
	int bfs()
	{
		fr(i,1,m) cur[i]=begin[i];
		fr(i,1,m) d[i]=inf;
		d[T]=0; q[l=r=1]=T;
		while(l<=r)
		{
			int u=q[l++];
			fo(i,u) if(w[i^1]&&d[u]+1<d[to[i]])
			{
				d[to[i]]=d[u]+1; q[++r]=to[i];
			}
		}
		fr(i,1,m) cur[i]=begin[i];
		return d[S]!=inf;
	}
	int dfs(int u,int F)
	{
		if(!F||u==T) return F;
		int ans=0;
		fo(i,u) if(w[i]&&d[u]-1==d[to[i]])
		{
			int f=dfs(to[i],std::min(w[i],F));
			w[i]-=f; w[i^1]+=f; F-=f; ans+=f;
		}
		return ans;
	}
	int main()
	{
		n=read(); S=++m; T=++m; e=1;
		fr(i,1,n) a[i]=read()+1;
		fr(i,1,n) b[i]=read()+1;
		fr(i,1,n) if(!id[i])
		{
			int I=i; m++;
			do{ id[I]=m; I=a[I]; } while(I!=i);
		}
		fr(i,1,n) if(!Id[i])
		{
			int I=i; m++;
			do{ Id[I]=m; I=b[I]; } while(I!=i);
		}
		ans=n;
		fr(i,1,n)
		{
			if(a[i]==b[i]){ if(a[i]!=i){ add(id[i],Id[i],1); add(Id[i],id[i],1); } else ans--; }
			else if(a[i]==i){ add(Id[i],T,1); add(T,Id[i],0); }
			else if(b[i]==i){ add(S,id[i],1); add(id[i],S,0); }
			else{ add(id[i],Id[i],0); add(Id[i],id[i],1); }
		}
		while(bfs()) ans-=dfs(S,inf);
		printf("%d\n",ans);
		return 0;
	}
}
int main()
{
	return run::main();
}