#include <iostream>
#include <algorithm>
#include <queue>

namespace fio {
	const int S = 1 << 21 | 1;
	char ibuf[S], *is, *it, c;
	char obuf[S], *os = obuf, *ot = os + S - 1, qu[55], qr;
	#define gc() (is == it ? (it = (is = ibuf) + fread(ibuf, 1, S, stdin), (is == it ? EOF : *is++)) : *is++)
	#define flush() (fwrite(obuf, 1, os - obuf, stdout), os = obuf)
	inline void putc(char c) {
		*os++ = c;
		if (os == ot) flush();
	}
	template<typename T>
	inline void in(T &x) {
		for (c = gc(); c < '0' || c > '9'; c = gc());
		for (x = 0; c >= '0' && c <= '9'; x = x * 10 + (c ^ 48), c = gc());
	}
	template<typename T>
	inline void out(T x) {
		if (!x) putc('0');
		while (x) qu[++qr] = x % 10 + 48, x /= 10;
		while (qr) putc(qu[qr--]);
	}
	struct f_ { ~f_() { flush(); } } io_f_;
}

namespace flw {
	const int N = 5000000 + 7;
	const int INF = 1 << 29;

	struct flow {
		int n, st, ed;
		int cur[N], vis[N], dis[N];
		struct edge { int to, nex, cap; } e[N];
		int fir[N], eid = 1;

		void addedge(int u, int v, int c);
		void addflow(int u, int v, int c);
		int dinic();
		int bfs();
		int dfs(int s, int f);
	};

	void flow::addedge(int u, int v, int c) {
		e[++eid] = (edge){ v, fir[u], c }, fir[u] = eid;
	}
	void flow::addflow(int u, int v, int c) {
		addedge(u, v, c), addedge(v, u, 0);
	}

	int flow::dinic() {
		int maxflow = 0, f;
		while (bfs()) while (f = dfs(st, INF)) maxflow += f;
		return maxflow;
	}
	int flow::bfs() {
		std::fill(dis + 1, dis + n + 1, -1);
		std::copy(fir + 1, fir + n + 1, cur + 1);
		std::queue <int> q;
		dis[ed] = 0, q.push(ed);
		for (int s; q.size(); ) {
			s = q.front(), q.pop();
			for (int i = fir[s]; i; i = e[i].nex)
				if (dis[e[i].to] == -1 && e[i ^ 1].cap)
					dis[e[i].to] = dis[s] + 1, q.push(e[i].to);
		}
		return dis[st] != -1;
	}
	int flow::dfs(int s, int f) {
		if (s == ed) return f;
		vis[s] = 1;
		int t, u = 0;
		for (int &i = cur[s]; i; i = e[i].nex) {
			if (vis[e[i].to] || !e[i].cap || dis[s] != dis[e[i].to] + 1) continue;
			t = dfs(e[i].to, std::min(f - u, e[i].cap));
			e[i].cap -= t, e[i ^ 1].cap += t, u += t;
			if (u == f) break;
		}
		return vis[s] = 0, u;
	}
};

using flw::INF;

const int N = 200000 + 7;

int n;
int p[N], g[N];
std::vector<std::pair<int, int>> e[N];
int m;
flw::flow f;

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	fio::in(n);
	for (int i = 1; i <= n * 2; ++i) fio::in(p[i]), p[i] += 1 + (i > n ? n : 0);
	for (int i = 1; i <= n * 2; ++i) {
		if (g[i]) continue;
		g[i] = p[i] != i ? ++m : (i <= n ? -1 : -2);
		for (int j = p[i]; j != i; j = p[j]) g[j] = g[i];
	}
	g[2 * n + 1] = ++m, g[2 * n + 2] = ++m;
	for (int i = 1; i <= n * 2; ++i)
		if (g[i] < 0) g[i] = g[2 * n - g[i]];

	f.st = m - 1, f.ed = f.n = m;
	auto insert = [&](int u, int v, int w) {
		e[g[u]].push_back(std::pair<int, int>(g[v], w));
	};
	for (int i = 1; i <= n; ++i) {
		insert(i, n + i, 1);
		if (p[i] + n == p[n + i]) insert(n + i, i, 1);
	}
	for (int i = 1; i <= f.n; ++i) {
		std::sort(e[i].begin(), e[i].end());
		for (int j = 0, k; j < e[i].size(); ++j) {
			k = e[i][j].second;
			while (j + 1 < e[i].size() && e[i][j + 1].first == e[i][j].first)
				k += e[i][++j].second;
			f.addflow(i, e[i][j].first, k);
		}
	}
	fio::out(n - f.dinic());
	return 0;
}


Measured memory_bytes: 27776