#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2020;
vector<int> Gph[2][NMAX];
int N, A, B, K;
int st[2][NMAX], dr[2][NMAX], edges[2][NMAX];
int val[2][NMAX][NMAX];
int dp[NMAX / 2];
void dfs(int node) {
  if (node != 1) edges[K][node] = 1;
  for (int i = 0; i < Gph[K][node].size(); i++) {
    int v = Gph[K][node][i];
    dfs(v);
    st[K][node] = min(st[K][node], st[K][v]);
    dr[K][node] = max(dr[K][node], dr[K][v]);
    edges[K][node] += edges[K][v];
  }
  val[K][st[K][node]][dr[K][node]] =
      max(val[K][st[K][node]][dr[K][node]], edges[K][node]);
}
int main() {
  scanf("%d%d", &N, &A);
  int x;
  K = 0;
  st[K][1] = A + 1;
  dr[K][1] = 0;
  for (int i = 2; i <= A; i++) {
    st[K][i] = A + 1;
    dr[K][i] = 0;
    scanf("%d", &x);
    Gph[K][x].push_back(i);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &x);
    st[K][x] = dr[K][x] = i;
  }
  dfs(1);
  scanf("%d", &B);
  K = 1;
  st[K][1] = B + 1;
  dr[K][1] = 0;
  for (int i = 2; i <= B; i++) {
    st[K][i] = B + 1;
    dr[K][i] = 0;
    scanf("%d", &x);
    Gph[K][x].push_back(i);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &x);
    st[K][x] = dr[K][x] = i;
  }
  dfs(1);
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j++)
      dp[j] = max(dp[j], dp[i - 1] + max(val[0][i][j], val[1][i][j]));
  printf("%d", dp[N]);
  return 0;
}
