#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using dd = double;
using vdd = std::vector<dd>;
using vvdd = std::vector<vdd>;
using vvvdd = std::vector<vvdd>;

constexpr ll INF = 1LL << 60;
constexpr dd EPS = 1e-11;

//cin,cout高速化のおまじない＋桁数指定
struct Fast{
	Fast(){
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast;

#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, N-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, N-1)
#define EACH(e, v) for (auto&& e : v)

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){T m=v[S]; REPS(i,S,E)chmax(m,v[i]); return m;}//v[S]～v[E]の最大値
template<class T> inline T MinE(vector<T>&v,ll S,ll E){T m=v[S]; REPS(i,S,E)chmin(m,v[i]); return m;}//v[S]～v[E]の最小値
template<class T> inline T MaxE(vector<T> &v, ll N) { return MaxE(v, 0, N - 1); } //先頭N個中の最大値
template<class T> inline T MinE(vector<T> &v, ll N) { return MinE(v, 0, N - 1); }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v, (ll)v.size()); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v, (ll)v.size()); }
template<class T> inline ll MaxI(vector<T>&v,ll S,ll E){ll m=S; REPS(i,S,E){if(v[i]>v[m])m=i;} return m;}
template<class T> inline ll MinI(vector<T>&v,ll S,ll E){ll m=S; REPS(i,S,E){if(v[i]<v[m])m=i;} return m;}
template<class T> inline ll MaxI(vector<T> &v, ll N) { return MaxI(v, 0, N - 1); }
template<class T> inline ll MinI(vector<T> &v, ll N) { return MinI(v, 0, N - 1); }
template<class T> inline ll MaxI(vector<T> &v) { return MaxI(v, (ll)v.size()); }
template<class T> inline ll MinI(vector<T> &v) { return MinI(v, (ll)v.size()); }
template<class T> inline T Sum(vector<T> &v, ll S, ll E){ T s=v[S]; REPS(i, S+1, E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v, ll N) { return Sum(v, 0, N - 1); }
template<class T> inline T Sum(vector<T> &v) { return Sum(v, v.size()); }
template<class T> inline T POW(T a, ll n){ T r=1; for (; n>0; n>>=1, a*=a){ if (n&1)r*=a; } return r; }
inline ll POW(int a, ll n){ return POW((ll)a, n); }
inline ll MSB(ll a){for(ll o=63,x=-1;;){ll m=(o+x)/2; if(a<(1LL<<m))o=m; else x=m; if(o-x==1)return x;}}
inline ll CEIL(ll a, ll b){ return (a+b-1)/b; }

template<class T=ll> inline vector<T> cinv(ll N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
template<class T=ll, class S=ll> inline vector<pair<T, S>> cinv2(ll N){
	vector<pair<T, S>> v(N); REP(i,N){cin>>v[i].first>>v[i].second;} return move(v); }
template<class T=ll,class S=ll,class R=ll> inline vector<tuple<T, S, R>> cinv3(ll N){
	vector<tuple<T,S,R>> v(N); REP(i,N){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);} return move(v);}
template<class T=ll,class S=ll,class R=ll,class Q=ll> inline vector<tuple<T,S,R,Q>> cinv4(ll N){
	vector<tuple<T,S,R,Q>> v(N); REP(i,N){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i])>>get<3>(v[i]);} return move(v);}
template<class T> inline void coutv(vector<T> &v, char deli=' '){
	ll N=(ll)v.size(); REP(i,N){cout << v[i] << ((i==N-1)?'\n':deli);} }
template<class T> void bye(T a){cout << a << '\n'; exit(0);}


struct mll{
	static ll MOD;
	ll val;
	mll(ll v = 0): val(v % MOD){ if (val < 0) val += MOD; }
	mll operator - () const { return -val; }
	mll operator + (const mll &b) const { return val + b.val; }
	mll operator - (const mll &b) const { return val - b.val; }
	mll operator * (const mll &b) const { return val * b.val; }
	mll operator / (const mll &b) const { return mll(*this) /= b; }
	mll operator + (ll b) const { return *this + mll(b); }
	mll operator - (ll b) const { return *this - mll(b); }
	mll operator * (ll b) const { return *this * mll(b); }
	friend mll operator + (ll a, const mll &b) { return b + a; }
	friend mll operator - (ll a, const mll &b) { return -b + a; }
	friend mll operator * (ll a, const mll &b) { return b * a; }
	mll &operator += (const mll &b) { val=(val+b.val)%MOD; return *this; }
	mll &operator -= (const mll &b) { val=(val+MOD-b.val)%MOD; return *this; }
	mll &operator *= (const mll &b) { val=(val*b.val)%MOD; return *this; }
	mll &operator /= (const mll &b) {
		ll c=b.val, d=MOD, u=1, v=0;
		while (d){
			ll t = c / d;
			c -= t * d; swap(c, d);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	mll &operator += (ll b) { return *this += mll(b); }
	mll &operator -= (ll b) { return *this -= mll(b); }
	mll &operator *= (ll b) { return *this *= mll(b); }
	mll &operator /= (ll b) { return *this /= mll(b); }
	bool operator == (const mll &b) { return val == b.val; }
	bool operator != (const mll &b) { return val != b.val; }
	bool operator == (ll b) { return *this == mll(b); }
	bool operator != (ll b) { return *this != mll(b); }
	friend bool operator == (ll a, const mll &b) { return mll(a) == b.val; }
	friend bool operator != (ll a, const mll &b) { return mll(a) != b.val; }
	friend ostream &operator << (ostream &os, const mll &a) { return os << a.val; }
	friend istream &operator >> (istream &is, mll &a) { return is >> a.val; }
	static mll Combination(ll a, ll b){
		chmin(b, a-b);
		if (b<0) return mll(0);
		mll c = 1;
		REP(i, b) c *= a-i;
		REP(i, b) c /= i+1;
		return c;
	}
};
ll mll::MOD = (ll)(1e9 + 7);// 998244353LL;//(ll)(1e9 + 7);
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;



using GraphDinic = vector<vector<tuple<ll, ll, ll>>>;

//sからの距離を得る 容量0の辺は通らない
vll bfsLevel(ll s, GraphDinic &GD){
	vll level(GD.size(), -1);
	queue<ll> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()){
		ll v = que.front(); que.pop();
		EACH(e, GD[v]){
			ll u, cap, rev;
			tie(u, cap, rev) = e;
			if (cap > 0 && level[u] < 0){
				level[u] = level[v] + 1;
				que.push(u);
			}
		}
	}
	return move(level);
}


ll dfsFindPath(ll v, ll t, ll f, vll &level, vll &iter, GraphDinic &GD){
	if (v == t) return f;

	for (ll &i = iter[v]; i < (ll)GD[v].size(); i++){
		ll &u   = get<0>(GD[v][i]);
		ll &cap = get<1>(GD[v][i]);
		ll &rev = get<2>(GD[v][i]);

		if (cap > 0 && level[v]<level[u]){
			ll d = dfsFindPath(u, t, min(f, cap), level, iter, GD);
			if (d > 0){
				cap -= d;
				get<1>(GD[u][rev]) += d;
				return d;
			}
		}
	}
	return 0;
}


//通常グラフ、逆辺がないグラフ用。逆辺を張る処理が冒頭に入る。
ll max_flow1(vector<vector<pair<ll,ll>>> &G, ll s, ll t){
	//Dinic法用に逆辺ありのグラフを作成
	GraphDinic GD(G.size());
	REP(v, (ll)G.size()){
		EACH(e, G[v]){
			ll u, cap;
			tie(u, cap) = e;
			GD[v].emplace_back(u, cap, (ll)GD[u].size());
			GD[u].emplace_back(v, 0, (ll)GD[v].size() - 1);
		}
	}
	
	ll flow = 0;
	while (true){
		vll level = bfsLevel(s, GD);
		if (level[t] < 0) return flow;

		vll iter(GD.size(), 0);
		ll f;
		while ((f = dfsFindPath(s, t, INF, level, iter, GD)) > 0){
			flow += f;
		}
	}
}

//Dinic法用グラフを直接入力する版
ll max_flow(GraphDinic &GD, ll s, ll t)
{
	ll flow = 0;
	while (true){
		vll level = bfsLevel(s, GD);
		if (level[t] < 0) return flow;

		vll iter(GD.size(), 0);
		ll f;
		while ((f = dfsFindPath(s, t, INF, level, iter, GD)) > 0){
			flow += f;
		}
	}
}


//v→uに重みwを張る
void link(GraphDinic &to, ll v, ll u, ll w){
	to[v].emplace_back(u, w, (ll)to[u].size());
	to[u].emplace_back(v, 0, (ll)to[v].size()-1);
}


void solve()
{
	ll N;
	cin >> N;
	auto P = cinv(N);
	auto Q = cinv(N);

	ll s = 0;
	ll t = 1;
	ll gId = 2;
	vll gP(N, -1);
	vll gQ(N, -1);

	REP(i, N){
		if (gP[i] != -1) continue;
		ll j = i;
		while (true){
			gP[j] = gId;
			j = P[j];
			if (gP[j] != -1) break;
		}
		gId++;
	}
	REP(i, N){
		if (gQ[i] != -1) continue;
		ll j = i;
		while (true){
			gQ[j] = gId;
			j = Q[j];
			if (gQ[j] != -1) break;
		}
		gId++;
	}
	ll gNum = gId;

	map<pair<ll, ll>, ll> idx;
	GraphDinic to(gNum);

	REP(i, N){
		if (i == P[i] && i == Q[i]){
			link(to, s, gQ[i], INF);
			link(to, gQ[i], gP[i], 1);
			link(to, gP[i], t, INF);
		}
		else if (i == P[i]){
			link(to, gQ[i], gP[i], 1);
			link(to, gP[i], t, INF);
		}
		else if (i == Q[i]){
			link(to, s, gQ[i], INF);
			link(to, gQ[i], gP[i], 1);
		}
		else{
			ll v = gQ[i];
			ll u = gP[i];
			if (idx.count(make_pair(v, u)) == 0){
				ll vIdx = (ll)to[v].size();
				ll uIdx = (ll)to[u].size();
				to[v].emplace_back(u, 0, uIdx);
				to[u].emplace_back(v, 0, vIdx);
				idx[make_pair(v, u)] = vIdx;
				idx[make_pair(u, v)] = uIdx;
			}
			ll vIdx = idx[make_pair(v, u)];
			get<1>(to[v][vIdx]) += 1;
			if (P[i] == Q[i]){
				ll uIdx = get<2>(to[v][vIdx]);
				get<1>(to[u][uIdx]) += 1;
			}
		}
	}

	ll ans = N - max_flow(to, s, t);
	cout << ans << '\n';
}

int main(){
	solve();
	return 0;
}


Measured memory_bytes: 24960