#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int n, a[maxn], b[maxn], f[maxn >> 1][maxn >> 1];
struct Tree {
  int n, dep[maxn], fa[maxn][12];
  vector<int> g[maxn];
  void dfs(int x) {
    dep[x] = dep[fa[x][0]] + 1;
    for (int i = 1; i <= 11; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (auto y : g[x])
      if (y != fa[x][0]) dfs(y);
  }
  inline int deplca(int x, int y) {
    if (!x || !y) return 0;
    if (dep[x] < dep[y]) swap(x, y);
    for (int i = 11; i >= 0; i--)
      if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
    if (x == y) return dep[x];
    for (int i = 11; i >= 0; i--)
      if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
    return dep[fa[x][0]];
  }
  inline void init() {
    scanf("%d", &n);
    for (int i = 2; i <= n; i++)
      scanf("%d", &fa[i][0]), g[fa[i][0]].push_back(i);
    dfs(1);
  }
} T1, T2;
int main() {
  scanf("%d", &n);
  T1.init();
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  T2.init();
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  memset(f, inf, sizeof(f));
  a[0] = b[0] = 1, f[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < i; j++) {
      if (f[i - 1][j] != inf) {
        f[i][j] = min(f[i][j],
                      f[i - 1][j] + T1.dep[a[i]] - T1.deplca(a[i - 1], a[i]));
        f[i - 1][i] = min(f[i - 1][i],
                          f[i - 1][j] + T2.dep[b[i]] - T2.deplca(b[j], b[i]));
      }
      if (f[j][i - 1] != inf) {
        f[i][i - 1] = min(f[i][i - 1],
                          f[j][i - 1] + T1.dep[a[i]] - T1.deplca(a[j], a[i]));
        f[j][i] = min(f[j][i],
                      f[j][i - 1] + T2.dep[b[i]] - T2.deplca(b[i - 1], b[i]));
      }
    }
  int ans = inf;
  for (int i = 0; i < n; i++) ans = min(ans, min(f[n][i], f[i][n]));
  printf("%d\n", T1.n + T2.n - ans - 1);
  return 0;
}
