#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A;
  cin >> A;
  vector<int> P(A, -1);
  for (int i = 1; i < A; ++i) {
    cin >> P[i];
    --P[i];
  }
  vector<int> X(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
    --X[i];
  }
  int B;
  cin >> B;
  vector<int> Q(B, -1);
  for (int i = 1; i < B; ++i) {
    cin >> Q[i];
    --Q[i];
  }
  vector<int> Y(N);
  for (int i = 0; i < N; ++i) {
    cin >> Y[i];
    --Y[i];
  }
  vector<vector<int>> dp0(N, vector<int>(N + 1));
  for (int i = 0; i < N; ++i) {
    vector<int> deg(A);
    for (int j = 1; j < A; ++j) ++deg[P[j]];
    for (int j = i; j < N; ++j) {
      dp0[i][j + 1] = dp0[i][j];
      for (int u = X[j]; u; u = P[u]) {
        ++dp0[i][j + 1];
        if (--deg[P[u]] > 0) break;
      }
    }
  }
  vector<vector<int>> dp1(N, vector<int>(N + 1));
  for (int i = 0; i < N; ++i) {
    vector<int> deg(B);
    for (int j = 1; j < B; ++j) ++deg[Q[j]];
    for (int j = i; j < N; ++j) {
      dp1[i][j + 1] = dp1[i][j];
      for (int u = Y[j]; u; u = Q[u]) {
        ++dp1[i][j + 1];
        if (--deg[Q[u]] > 0) break;
      }
    }
  }
  vector<int> dp(N + 1);
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < i; ++j) {
      dp[i] = max(dp[i], dp[j] + max(dp0[j][i], dp1[j][i]));
    }
  }
  cout << dp[N] << endl;
  return 0;
}
