#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 100010;
int C[maxn];
int n;
inline int read() {
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {x = x * 10 + ch - 48; ch = getchar();}
return x * f;
}
int lowbit(int x) {
return x & (-x);
}
void update(int x, int v) {
for (int i = x; i <= n; i += lowbit(i)) {
C[i] = max(C[i], v);
}
}
int getmax(int x) {
int res = 0;
for (int i = x; i > 0; i -= lowbit(i)) {
res = max(res, C[i]);
}
return res;
}
int p1[maxn], p2[maxn];
vector<int> pos[maxn];
int dp[maxn];
int main() {
n = read();
n *= 5;
for (int i = 1; i <= n; i++) {
p1[i] = read();
}
for (int i = 1; i <= n; i++) {
p2[i] = read();
pos[p2[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
for (int j = 4; j >= 0; j--) {
int temp = max(temp, getmax(pos[p1[i]][j] - 1) + 1);
update(pos[p1[i]][j], temp);
dp[i] = max(dp[i], temp);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
return 0;
}