#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10, mod = 11092019;
int n, m[2], leaf[N][2], dep[N][2], p[16][2][N], pre[N][2], dist[N][N][2],
    dp[N][2];
vector<int> adj[N][2];
void predfs(int u, int pa, int lst, bool st) {
  p[0][st][u] = pa;
  dep[u][st] = dep[pa][st] + 1;
  pre[u][st] = lst;
  lst = (adj[u][st].size() > 1 ? u : lst);
  for (int v : adj[u][st]) {
    predfs(v, u, lst, st);
  }
}
pair<int, int> lca(int u, int v, bool st) {
  int dis = 0;
  if (dep[u][st] > dep[v][st]) swap(u, v);
  for (int j = 15; j >= 0; j--) {
    if (dep[v][st] - (1 << j) >= dep[u][st]) {
      dis += (1 << j);
      v = p[j][st][v];
    }
  }
  if (u == v) return {u, dis};
  dis += 2;
  for (int j = 15; j >= 0; j--) {
    if (p[j][st][u] != p[j][st][v]) {
      u = p[j][st][u];
      v = p[j][st][v];
      dis += (2 << j);
    }
  }
  return {p[0][st][u], dis};
}
int main() {
  scanf("%d", &n);
  for (int s = 0; s < 2; s++) {
    scanf("%d", &m[s]);
    for (int i = 2; i <= m[s]; i++) {
      int x;
      scanf("%d", &x);
      adj[x][s].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      leaf[i][s] = x;
    }
  }
  predfs(1, 1, 1, 0);
  predfs(1, 1, 1, 1);
  for (int j = 1; j < 16; j++) {
    for (int st = 0; st < 2; st++) {
      for (int i = 1; i <= m[st]; i++)
        p[j][st][i] = p[j - 1][st][p[j - 1][st][i]];
    }
  }
  for (int st = 0; st < 2; st++) {
    for (int i = 1; i <= n; i++) {
      int dis = 0;
      vector<int> sum(m[st] + 1, 0);
      for (int j = i; j <= n; j++) {
        int v = leaf[j][st];
        int u = pre[v][st];
        dis += dep[v][st] - dep[u][st];
        sum[u]++;
        while (sum[u] == adj[u][st].size()) {
          dis += dep[u][st] - dep[pre[u][st]][st];
          u = pre[u][st];
          sum[u]++;
        }
        dist[i][j][st] = dis;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int st = 0; st < 2; st++) {
      for (int j = i; j >= 1; j--)
        dp[i][st] = max(dp[i][st], dp[j - 1][1 - st] + dist[j][i][st]);
    }
  }
  printf("%d\n", max(dp[n][0], dp[n][1]));
  return 0;
}
