#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int N = 2005;
int i, j, k, l, n, a, b, c, tab1[N], leaf1[N], tab2[N], leaf2[N], ojciec1[N],
    ojciec2[N], w, w2, res[N][N], sum1[N][N], sum2[N][N], best[N], mat1[N],
    mat2[N];
vector<int> graf1[N], graf2[N];
void dfs(vector<int> graf[N], int leaf[N], int w) {
  if (leaf[w] != 0) {
    best[w] = leaf[w];
    return;
  }
  best[w] = INF;
  for (auto& w2 : graf[w]) {
    dfs(graf, leaf, w2);
    best[w] = min(best[w], best[w2]);
  }
}
bool cmp(int a, int b) { return best[a] < best[b]; }
int main() {
  scanf("%d", &n);
  scanf("%d", &a);
  for (i = 2; i <= a; i++) {
    scanf("%d", &c);
    graf1[c].push_back(i);
    ojciec1[i] = c;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &tab1[i]);
    leaf1[tab1[i]] = i;
  }
  scanf("%d", &b);
  for (i = 2; i <= b; i++) {
    scanf("%d", &c);
    graf2[c].push_back(i);
    ojciec2[i] = c;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &tab2[i]);
    leaf2[tab2[i]] = i;
  }
  dfs(graf1, leaf1, 1);
  for (i = 1; i <= a; i++) sort(graf1[i].begin(), graf1[i].end(), cmp);
  dfs(graf2, leaf2, 1);
  for (i = 1; i <= b; i++) sort(graf2[i].begin(), graf2[i].end(), cmp);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= a; j++) mat1[j] = graf1[j].size();
    sum1[i][i] = 0;
    for (j = i; j <= n; j++) {
      sum1[i][j] = i == j ? 0 : sum1[i][j - 1];
      w = tab1[j];
      while (w != 1) {
        sum1[i][j]++;
        w2 = ojciec1[w];
        mat1[w2]--;
        if (mat1[w2] > 0) break;
        w = w2;
      }
    }
    for (j = 1; j <= b; j++) mat2[j] = graf2[j].size();
    sum2[i][i] = 0;
    for (j = i; j <= n; j++) {
      sum2[i][j] = i == j ? 0 : sum2[i][j - 1];
      w = tab2[j];
      while (w != 1) {
        sum2[i][j]++;
        w2 = ojciec2[w];
        mat2[w2]--;
        if (mat2[w2] > 0) break;
        w = w2;
      }
    }
  }
  for (i = 1; i <= n; i++) res[i][i] = max(sum1[i][i], sum2[i][i]);
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) {
      res[i][j] = max(sum1[i][j], sum2[i][j]);
      for (k = i; k < j; k++) {
        res[i][j] = max(res[i][j], res[i][k] + sum1[k + 1][j]);
        res[i][j] = max(res[i][j], res[i][k] + sum2[k + 1][j]);
      }
    }
  printf("%d\n", res[1][n]);
  return 0;
}
