#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

template<typename T>
struct Dinic {
	const T INF = 1e9;
	const int INF1 = 1e9;
	struct edge {
		int a, b;
		T f, c;
	};
	int s, t;
	vector<edge> ed;
	int n;
	vector<vector<int> > eds;
	vector<T> dd;
	vector<int> pp;
	vector<int> inCut;
	Dinic(int N, int S, int TT) {
		n = N, s = S, t = TT;
		eds.clear();
		dd.clear();
		pp.clear();
		ed.clear();
		eds.resize(n);
		dd.resize(n);
		pp.resize(n);
		inCut.clear();
	}
	void add_edge(int a, int b, T c) {
		edge x;
		x.a = a;
		x.b = b;
		x.f = 0;
		x.c = c;
		eds[a].push_back(ed.size());
		eds[b].push_back(ed.size() + 1);
		ed.push_back(x);
		x.c = 0;
		swap(x.a, x.b);
		ed.push_back(x);
	}
	T dfs(int v, T fl) {
		if (v == t)
			return fl;
		if (dd[v] == dd[t])
			return 0;
		T sum = 0;
		for (; pp[v] < (int)eds[v].size(); ++pp[v]) {
			int e = eds[v][pp[v]];
			int u = ed[e].b;
			T fr = ed[e].c - ed[e].f;
			if (fr == 0 || dd[u] != dd[v] + 1 || pp[u] == (int)eds[u].size())
				continue;
			fr = dfs(u, min(fl, fr));
			ed[e].f += fr;
			ed[e ^ 1].f -= fr;
			sum += fr;
			fl -= fr;
			if (fl == 0)
				break;
		}
		return sum;
	}
	T flow() {
		T sum = 0;
		T lst = 0;
		do {
			lst = 0;
			fill(dd.begin(), dd.end(), INF1);
			dd[s] = 0;
			queue<int> qu;
			qu.push(s);
			while (!qu.empty()) {
				int x = qu.front();
				qu.pop();
				for (int i = 0; i < (int)eds[x].size(); ++i) {
					if (ed[eds[x][i]].f < ed[eds[x][i]].c) {
						int u = ed[eds[x][i]].b;
						if (dd[u] > dd[x] + 1)
							dd[u] = dd[x] + 1, qu.push(u);
					}
				}
			}
			if (dd[t] == INF)
				break;
			fill(pp.begin(), pp.end(), 0);
			lst = dfs(s, INF);
			sum += lst;
		} while (lst);
		return sum;
	}
	void dfs1(int s) {
		pp[s] = 1;
		for (int e: eds[s]) {
			if (ed[e].c != ed[e].f && !pp[ed[e].b])
				dfs1(ed[e].b);
		}
	}
	void markCut() {
		inCut.resize(ed.size());
		fill(pp.begin(), pp.end(), 0);
		dfs1(s);
		for (int i = 0; i < ed.size(); ++i)
			if (pp[ed[i].a] && !pp[ed[i].b])
				inCut[i] = 1;
			else
				inCut[i] = 0;
	}
};


const int N = 210000;

int n;
int p[N];
int cp[N];
int q[N];
int cq[N];

void dfsp(int v, int c) {
	cp[v] = c;
	if (cp[p[v]] == -1) {
		dfsp(p[v], c);
	}
}

void dfsq(int v, int c) {
	cq[v] = c;
	if (cq[q[v]] == -1) {
		dfsq(q[v], c);
	}
}

int cs[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> q[i];
	}
	int add = 0;
	for (int i = 0; i < n; ++i) {
		if (p[i] == i && q[i] == i) {
			++add;
		}
	}
	fill(cp, cp + n, -1);
	fill(cq, cq + n, -1);
	int cc = 0;
	for (int i = 0; i < n; ++i) {
		if (cp[i] == -1 && p[i] != i) {
			dfsp(i, cc++);
		}
	}
	int br = cc;
	for (int i = 0; i < n; ++i) {
		if (cq[i] == -1 && q[i] != i) {
			dfsq(i, cc++);
		}
	}
	Dinic<int> din(cc + 2, cc, cc + 1);
	for (int i = 0; i < n; ++i) {
		if (p[i] == i && q[i] != i) {
			++cs[cq[i]];
		}
		if (p[i] != i && q[i] == i) {
			++cs[cp[i]];
		}
		if (p[i] != i && q[i] != i) {
			din.add_edge(cq[i], cp[i], 1);
			if (p[i] == q[i]) {
				din.add_edge(cp[i], cq[i], 1);
			}
		}
	}
	for (int i = 0; i < br; ++i) {
		din.add_edge(cc, i, cs[i]);
	}
	for (int i = br; i < cc; ++i) {
		din.add_edge(i, cc + 1, cs[i]);
	}

	cout << n - din.flow() - add << "\n";
	return 0;
}




Measured memory_bytes: 19304