#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
const int logN = 11;
int x[2005];
vector<int> g[2005];
int par[logN][2005], depth[2005];
void dfs(int u, int p, int d) {
  depth[u] = d;
  par[0][u] = p;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p) continue;
    dfs(v, u, d + 1);
  }
}
int LCA(int a, int b) {
  if (depth[b] > depth[a]) swap(a, b);
  int diff = depth[a] - depth[b];
  for (int i = logN - 1; i >= 0; i--) {
    if ((diff >> i) & 1) a = par[i][a];
  }
  if (a == b) return a;
  for (int i = logN - 1; i >= 0; i--) {
    if (par[i][a] != par[i][b]) a = par[i][a], b = par[i][b];
  }
  return par[0][a];
}
int cost[2][2005][2005], dp[2][2005][2005];
int min(int a, int b) {
  if (a == -1 || a > b) return b;
  return a;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, a, b, p;
  scanf("%d%d", &n, &a);
  for (int i = 2; i <= a; i++) {
    scanf("%d", &p);
    g[p].push_back(i);
    g[i].push_back(p);
  }
  dfs(1, 0, 0);
  for (int j = 1; j < logN; j++) {
    for (int i = 1; i <= a; i++) {
      if (par[j - 1][i] != 0) par[j][i] = par[j - 1][par[j - 1][i]];
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    cost[0][i][i] = depth[x[i]];
    for (int j = 1; j < i; j++) {
      int y = LCA(x[i], x[j]);
      cost[0][j][i] = depth[x[i]] - depth[y];
    }
  }
  memset(par, 0, sizeof(par));
  memset(depth, 0, sizeof(depth));
  scanf("%d", &b);
  for (int i = 1; i <= b; i++) g[i].clear();
  for (int i = 2; i <= b; i++) {
    scanf("%d", &p);
    g[p].push_back(i);
    g[i].push_back(p);
  }
  dfs(1, 0, 0);
  for (int j = 1; j < logN; j++) {
    for (int i = 1; i <= b; i++) {
      if (par[j - 1][i] != 0) par[j][i] = par[j - 1][par[j - 1][i]];
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    cost[1][i][i] = depth[x[i]];
    for (int j = 1; j < i; j++) {
      int y = LCA(x[i], x[j]);
      cost[1][j][i] = depth[x[i]] - depth[y];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      dp[0][0][i] = cost[0][1][1];
      dp[1][0][i] = cost[1][1][1];
    } else {
      for (int j = 0; j < i - 1; j++) {
        dp[0][j][i] = min(dp[0][j][i], dp[0][j][i - 1] + cost[0][i - 1][i]);
        if (j != 0)
          dp[0][i - 1][i] =
              min(dp[0][i - 1][i], dp[1][j][i - 1] + cost[0][j][i]);
        else
          dp[0][i - 1][i] =
              min(dp[0][i - 1][i], dp[1][j][i - 1] + cost[0][i][i]);
      }
      for (int j = 0; j < i - 1; j++) {
        dp[1][j][i] = min(dp[1][j][i], dp[1][j][i - 1] + cost[1][i - 1][i]);
        if (j != 0)
          dp[1][i - 1][i] =
              min(dp[1][i - 1][i], dp[0][j][i - 1] + cost[1][j][i]);
        else
          dp[1][i - 1][i] =
              min(dp[1][i - 1][i], dp[0][j][i - 1] + cost[1][i][i]);
      }
    }
  }
  int ans = 1e9;
  for (int i = 0; i <= n; i++) {
    if (dp[0][i][n] != -1) ans = min(ans, dp[0][i][n]);
    if (dp[1][i][n] != -1) ans = min(ans, dp[1][i][n]);
  }
  printf("%d\n", a + b - 2 - ans);
}
