#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#define MAX_V 200010

typedef int F;
const F INF = TEN(9);

struct edge {
	int to, rev;
	F cap;
	edge(int to, F cap, int rev) : to(to), cap(cap), rev(rev) {};
};

vector<edge> G[MAX_V];
int level[MAX_V]; 
int iter[MAX_V]; 

void add_edge(int from, int to, F cap) {
	G[from].emplace_back(to, cap, (int)G[to].size());
	G[to].emplace_back(from, 0, (int)G[from].size() - 1);
}

void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);

	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (edge &e : G[v]) {
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

F dfs(int v, int t, F f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			F d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

F max_flow(int s, int t) {
	F flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		F f;
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
}

int main() {
	int N; cin >> N;
	vi P(N), Q(N);
	vi cmP(N, -1), cmQ(N, -1);

	rep(i, N) cin >> P[i];
	rep(i, N) cin >> Q[i];

	int nowP = 0, nowQ = 0;
	rep(i, N) {
		if (cmP[i] == -1 && P[i] != i) {
			int p = i;
			while (cmP[p] == -1) {
				cmP[p] = nowP;
				p = P[p];
			}
			++nowP;
		}
		if (cmQ[i] == -1 && Q[i] != i) {
			int q = i;
			while (cmQ[q] == -1) {
				cmQ[q] = nowQ;
				q = Q[q];
			}
			++nowQ;
		}		
	}

	int num = N;
	int s = 0, t = 1 + nowP + nowQ; //V = t + 1
	int same = 0;

	rep(i, N) {
		if (P[i] == i && Q[i] == i) {
			++same;
		} else if (P[i] == i) {
			add_edge(s, cmQ[i] + 1 + nowP, 1);
		} else if (Q[i] == i) {
			add_edge(cmP[i] + 1, t, 1);
		} else {
			add_edge(cmP[i] + 1, cmQ[i] + 1 + nowP, 1);
			if (P[i] == Q[i]) {
				add_edge(cmQ[i] + 1 + nowP, cmP[i] + 1, 1);
			}
		}
	}

	same += max_flow(s, t);

	cout << N - same << endl;

	return 0;
}