#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
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*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
queue<int>q;
struct node
{
	int x,y,c,next;
}a[400010];int len,last[200010],cur[200010]; 
inline void trins(int x,int y,int c)
{
	len++;
	a[len].x=x;a[len].y=y;a[len].c=c;
	a[len].next=last[x];last[x]=len;
}
inline void ins(int x,int y,int c){trins(x,y,c),trins(y,x,0);}
int st,ed,d[200010];
inline bool bfs()
{
	memset(d,0,sizeof(d));d[st]=1;
	q.push(st);
	while(q.empty()!=true)
	{
		int x=q.front();q.pop();
		for(int k=last[x];k;k=a[k].next)
		{
			if(!a[k].c)continue;
			int y=a[k].y;
			if(!d[y])d[y]=d[x]+1,q.push(y);
		}
	}
	if(!d[ed])return false;
	else return true;
}
inline int dinic(int x,int flow)
{
	if(x==ed)return flow;
	int sum=0;
	for(int &k=cur[x];k;k=a[k].next)
	{
		if(!a[k].c)continue;
		if(sum==flow)break;
		int y=a[k].y;
		if(d[y]==d[x]+1)
		{
			int uf=dinic(y,min(a[k].c,flow-sum));
			a[k].c-=uf,a[k^1].c+=uf;sum+=uf;
		}
	}if(!sum)d[x]=0;
	return sum;
}
int fa[2][100010],belong[2][100010];
inline int findfa(int id,int x)
{
	if(fa[id][x]!=x)fa[id][x]=findfa(id,fa[id][x]);
	return fa[id][x];
}
int p[2][100010];
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read(),tot=0;
	for(int i=1;i<=n;i++)fa[0][i]=fa[1][i]=i;
	for(int i=1;i<=n;i++)
	{
		p[0][i]=read()+1;
		int fx=findfa(0,i),fy=findfa(0,p[0][i]);
		if(fx!=fy)fa[0][fx]=fy;
	}
	for(int i=1;i<=n;i++)if(findfa(0,i)==i)belong[0][i]=++tot;
	for(int i=1;i<=n;i++)
	{
		p[1][i]=read()+1;
		int fx=findfa(1,i),fy=findfa(1,p[1][i]);
		if(fx!=fy)fa[1][fx]=fy;
	}
	for(int i=1;i<=n;i++)if(findfa(1,i)==i)belong[1][i]=++tot;
	len++;st=0,ed=++tot;int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans++;int f0=fa[0][i],f1=fa[1][i];
		if(p[0][i]==i)
		{
			if(p[1][i]!=i)ins(st,belong[1][f1],1);
			else ans--;
		}
		else if(p[1][i]==i)ins(belong[0][f0],ed,1);
		else
		{
			if(p[0][i]==p[1][i])ins(belong[0][f0],belong[1][f1],1),ins(belong[1][f1],belong[0][f0],1);
			else ins(belong[0][f0],belong[1][f1],1);
		}
	}
	while(bfs()==true)
	{
		for(int i=0;i<=tot;i++)cur[i]=last[i];
		ans-=dinic(st,inf);
	}
	pr2(ans);
	return 0;
}