#include <bits/stdc++.h>
using namespace std;
const long long INF = (1e18) + 10;
struct edge {
  int v, nxt;
} e[(2010 + 10) * 2][2];
int en[2];
int head[(2010 + 10)][2];
int dp[(2010 + 10)];
int ers[1010][1010][2];
int sz[(2010 + 10)][2], Lb[(2010 + 10)][2], Rb[(2010 + 10)][2];
int n, an, bn;
void adde(int u, int v, int tg) {
  int &ens = en[tg];
  e[++ens][tg].v = v;
  e[ens][tg].nxt = head[u][tg];
  head[u][tg] = ens;
}
void dfs(int x, int pre, int tg) {
  sz[x][tg] = 1;
  for (int i = head[x][tg]; i != -1; i = e[i][tg].nxt) {
    int v = e[i][tg].v;
    if (v == pre) continue;
    dfs(v, x, tg);
    Lb[x][tg] = min(Lb[x][tg], Lb[v][tg]);
    Rb[x][tg] = max(Rb[x][tg], Rb[v][tg]);
    sz[x][tg] += sz[v][tg];
  }
  ers[Lb[x][tg]][Rb[x][tg]][tg] = max(ers[Lb[x][tg]][Rb[x][tg]][tg], sz[x][tg]);
  return;
}
int main() {
  memset(head, -1, sizeof(head));
  memset(en, 0, sizeof(en));
  memset(Lb, 0x3f, sizeof(Lb));
  int n;
  scanf("%d", &n);
  scanf("%d", &an);
  for (int i = 1; i < an; i++) {
    int pi;
    scanf("%d", &pi);
    adde(i + 1, pi, 0);
    adde(pi, i + 1, 0);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    Lb[x][0] = i;
    Rb[x][0] = i;
  }
  scanf("%d", &bn);
  for (int i = 1; i < bn; i++) {
    int pi;
    scanf("%d", &pi);
    adde(i + 1, pi, 1);
    adde(pi, i + 1, 1);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    Lb[x][1] = i;
    Rb[x][1] = i;
  }
  for (int i = 0; i < 2; i++) dfs(1, -1, i);
  ers[1][n][0]--;
  ers[1][n][1]--;
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      for (int tg = 0; tg < 2; tg++) {
        dp[i] = max(dp[i], dp[j - 1] + ers[j][i][tg]);
      }
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
