#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
struct LowestCommonAncestor {
  vector<vector<int>> g;
  int root;
  vector<int> parent[25];
  vector<int> depth;
  LowestCommonAncestor(int V, int root_) : g(V), depth(V) {
    root = root_;
    for (int i = 0; i < 25; i++) parent[i].resize(V);
  }
  void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }
  void dfs(int v, int p, int d) {
    parent[0][v] = p;
    depth[v] = d;
    for (int i = 0; i < g[v].size(); i++) {
      if (g[v][i] != p) dfs(g[v][i], v, d + 1);
    }
  }
  void init(int V) {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < 25; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0)
          parent[k + 1][v] = -1;
        else
          parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }
  int query(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < 25; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (int k = 25 - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
int dp[1010][1010][2];
const int INF = 1e9;
void chmin(int &a, int b) {
  if (a > b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A;
  cin >> A;
  vector<int> PA(A);
  for (int i = 0; i < (A - 1); ++i) {
    cin >> PA[i];
    PA[i]--;
  }
  vector<int> X(N + 1, 0);
  for (int i = 0; i < (N); ++i) {
    cin >> X[i + 1];
    X[i + 1]--;
  }
  int B;
  cin >> B;
  vector<int> PB(B);
  for (int i = 0; i < (B - 1); ++i) {
    cin >> PB[i];
    PB[i]--;
  }
  vector<int> Y(N + 1, 0);
  for (int i = 0; i < (N); ++i) {
    cin >> Y[i + 1];
    Y[i + 1]--;
  }
  LowestCommonAncestor lcaA(A, 0), lcaB(B, 0);
  for (int i = 0; i < A - 1; i++) lcaA.add_edge(PA[i], i + 1);
  for (int i = 0; i < B - 1; i++) lcaB.add_edge(PB[i], i + 1);
  lcaA.init(A);
  lcaB.init(B);
  for (int i = 0; i < (N + 1); ++i)
    for (int j = 0; j < (N + 1); ++j)
      for (int k = 0; k < (2); ++k) dp[i][j][k] = INF;
  dp[0][0][0] = 0;
  dp[0][0][1] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k < 2; k++) {
        if (dp[i][j][k] == INF) continue;
        for (int l = 0; l < 2; l++) {
          int nj = j, nk = l;
          int tar = j;
          int neco = 0;
          if (l == k)
            tar = i;
          else
            nj = i;
          if (l == 0) {
            int lc = lcaA.query(X[i + 1], X[tar]);
            neco = lcaA.depth[X[i + 1]] - lcaA.depth[lc];
          } else {
            int lc = lcaB.query(Y[i + 1], Y[tar]);
            neco = lcaB.depth[Y[i + 1]] - lcaB.depth[lc];
          }
          chmin(dp[i + 1][nj][nk], dp[i][j][k] + neco);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= N; i++)
    for (int k = 0; k < 2; k++) {
      if (dp[N][i][k] == INF) continue;
      if (ans < A - 1 + B - 1 - dp[N][i][k]) ans = A - 1 + B - 1 - dp[N][i][k];
    }
  cout << ans << endl;
  return 0;
}
