#include <bits/stdc++.h>
using namespace std;
const int N = 2200;
int n, A, B;
struct mp {
  int l[N], r[N];
  vector<int> V[N];
  mp() { memset(l, 0x3f, sizeof l); }
  void add(int x, int y) { V[x].push_back(y), V[y].push_back(x); }
  void dfs(int x, int f) {
    for (int i = 0; i < V[x].size(); i++)
      if (V[x][i] != f)
        dfs(V[x][i], x), l[x] = min(l[x], l[V[x][i]]),
                         r[x] = max(r[x], r[V[x][i]]);
  }
} G, T;
priority_queue<int> P, Q;
int dp[N][2];
int main() {
  scanf("%d", &n);
  scanf("%d", &A);
  for (int i = 2, f; i <= A; i++) scanf("%d", &f), G.add(i, f);
  for (int i = 1, x; i <= n; i++) scanf("%d", &x), G.l[x] = G.r[x] = i;
  scanf("%d", &B);
  for (int i = 2, f; i <= B; i++) scanf("%d", &f), T.add(i, f);
  for (int i = 1, x; i <= n; i++) scanf("%d", &x), T.l[x] = T.r[x] = i;
  G.dfs(1, 0), T.dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 2; j <= A; j++) G.r[j] <= i ? P.push(-G.l[j]) : (void)0;
    for (int j = 2; j <= B; j++) T.r[j] <= i ? Q.push(-T.l[j]) : (void)0;
    for (int j = 0; j < i; j++) {
      while (P.size() && -P.top() <= j) P.pop();
      while (Q.size() && -Q.top() <= j) Q.pop();
      dp[i][0] = max(dp[i][0], dp[j][1] + (int)P.size()),
      dp[i][1] = max(dp[i][1], dp[j][0] + (int)Q.size());
    }
    while (P.size()) P.pop();
    while (Q.size()) Q.pop();
  }
  printf("%d\n", max(dp[n][0], dp[n][1]));
}
