#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e6 + 5, inf = 1e9;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
queue <int> Q;
int n, s, t, cnt, tot = 1, p[N], q[N], tag[N], cur[N], dep[N], head[N], to[N], val[N], nxt[N];
void add(int x, int y, int c1, int c2) {
	to[++ tot] = y; val[tot] = c1; nxt[tot] = head[x]; head[x] = tot;
	to[++ tot] = x; val[tot] = c2; nxt[tot] = head[y]; head[y] = tot;
}
int bfs() {
	for(int i = s; i <= t; ++ i) cur[i] = head[i];
	for(int i = s; i <= t; ++ i) dep[i] = 0;
	dep[s] = 1; queue <int> q; q.push(s);
	while(! q.empty()) {
		int x = q.front(); q.pop();
		for(int i = head[x]; i; i = nxt[i]) {
			if(val[i] && dep[to[i]] == 0) {
				dep[to[i]] = dep[x] + 1;
				q.push(to[i]);
			}
		}
	}
	return dep[t] > 0;
}
int dfs(int x, int flow) {
	if(x == t) return flow;
	int up = 0;
	for(int &i = cur[x]; i; i = nxt[i]) {
		if(val[i] && dep[to[i]] == dep[x] + 1) {
			int tmp = dfs(to[i], Min(flow, val[i]));
			if(tmp == 0) dep[to[i]] = 0;
			val[i] -= tmp; val[i ^ 1] += tmp;
			flow -= tmp; up += tmp;
			if(flow == 0) return up;
		}
	}
	return up;
}
int Dinic() {
	int res = 0, flow;
	while(bfs()) while(flow = dfs(s, 2e9)) res += flow;
	return res;
}
int main() {
	n = read(); cnt = 2 * n;
	for(int i = 1; i <= n; ++ i) p[i] = read() + 1, tag[i] = 0;
	for(int i = 1; i <= n; ++ i) {
		if(tag[i]) continue;
		int q = i; cnt ++;
		do {
			tag[q] = 1; q = p[q];
			add(cnt, q, inf, inf);
		} while(q != i);
	}
	for(int i = 1; i <= n; ++ i) q[i] = read() + 1, tag[i] = 0;
	for(int i = 1; i <= n; ++ i) {
		if(tag[i]) continue;
		int p = i; cnt ++;
		do {
			tag[p] = 1; p = q[p];
			add(cnt, p + n, inf, inf);
		} while(p != i);
	}
	s = 0; t = cnt + 1;
	for(int i = 1; i <= n; ++ i) {
		if(p[i] == i && q[i] == i) add(s, i, 1, 0), add(i, t, 1, 0);
		if(p[i] == i && q[i] != i) add(s, i + n, 1, 0);
		if(p[i] != i && q[i] == i) add(i, t, 1, 0);
		if(p[i] != i && q[i] != i && p[i] == q[i]) add(i, i + n, 1, 1);
		if(p[i] != i && q[i] != i && p[i] != q[i]) add(i, i + n, 1, 0);
	}
	printf("%d\n", n - Dinic());
	return 0;
}
