#include <bits/stdc++.h>
using namespace std;
int n, sl, fh, ans, lg[4096], f[1024][1024];
int rd() {
  sl = 0;
  fh = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') sl = sl * 10 + ch - '0', ch = getchar();
  return sl * fh;
}
struct Tree {
  int N, a[2048], s[2048], d[2048], fa[2048], f[1024][1024];
  void init() {
    N = rd();
    for (int i = 2; i <= N; ++i) fa[i] = rd();
    for (int i = 1; i <= n; ++i) a[i] = rd();
    for (int i = 1; i <= N; ++i) s[fa[i]]++;
    for (int x, u, l = 1; l <= n; ++l) {
      for (int i = 1; i <= N; ++i) d[i] = s[i];
      x = 0;
      for (int r = l; r <= n; ++r) {
        u = a[r];
        while (u != 1 && !d[u]) {
          u = fa[u];
          d[u]--;
          x++;
        }
        f[l][r] = x;
      }
    }
  }
} T1, T2;
void upd(int &x, int y) {
  if (x < y) x = y;
}
int main() {
  for (int i = 2; i < 4096; ++i) lg[i] = lg[i >> 1] + 1;
  n = rd();
  T1.init();
  T2.init();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      upd(f[max(i, j) + 1][j],
          f[i][j] - T1.f[j + 1][max(i, j)] + T1.f[j + 1][max(i, j) + 1]);
      upd(f[i][max(i, j) + 1],
          f[i][j] - T2.f[i + 1][max(i, j)] + T2.f[i + 1][max(i, j) + 1]);
    }
  for (int i = 0; i < n; ++i) upd(ans, f[i][n]), upd(ans, f[n][i]);
  printf("%d\n", ans);
  return 0;
}
