#include <bits/stdc++.h>
using namespace std;
int N;
int M[2];
int P[2][2010];
vector<int> E[2][2010];
int R[2][2010];
int D[2][2010];
int dif[2][2010][2010];
int dp[2010][2010];
void dfs(int id, int cur, int d) {
  D[id][cur] = d;
  for (auto& e : E[id][cur]) dfs(id, e, d + 1);
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (x = 0; x < (2); x++) {
    cin >> M[x];
    for (i = 0; i < (M[x] - 1); i++) {
      cin >> P[x][i + 2];
      E[x][P[x][i + 2]].push_back(i + 2);
    }
    dfs(x, 1, 0);
    for (i = 0; i < (N); i++) {
      cin >> R[x][i];
    }
    for (i = 0; i < (N); i++) {
      dif[x][0][i + 1] = D[x][R[x][i]];
    }
    for (j = 0; j < (N); j++)
      for (i = 0; i < (j); i++) {
        int a = R[x][i];
        int b = R[x][j];
        while (D[x][a] > D[x][b]) a = P[x][a];
        while (D[x][a] < D[x][b]) b = P[x][b];
        while (a != b) {
          a = P[x][a];
          b = P[x][b];
        }
        dif[x][i + 1][j + 1] = D[x][R[x][j]] - D[x][b];
      }
  }
  for (x = 0; x < (N + 1); x++)
    for (y = 0; y < (N + 1); y++) dp[x][y] = 101010;
  dp[0][1] = dif[1][0][1];
  dp[1][0] = dif[0][0][1];
  int mi = 1 << 20;
  if (N == 1) mi = min(dp[0][1], dp[1][0]);
  for (x = 0; x < (N + 1); x++)
    for (y = 0; y < (N + 1); y++)
      if (x != y) {
        int nex = max(x, y) + 1;
        dp[x][nex] = min(dp[x][nex], dp[x][y] + dif[1][y][nex]);
        dp[nex][y] = min(dp[nex][y], dp[x][y] + dif[0][x][nex]);
        if (nex == N) mi = min({mi, dp[x][nex], dp[nex][y]});
      }
  cout << (M[0] + M[1] - 2) - mi << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
