#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 500;
vector<int> G[2][maxn];
int val[2][maxn][maxn], l[2][maxn], r[2][maxn], sz[2][maxn];
int n, a, x, dp[maxn];
void dfs(int _, int u) {
  if (u != 1) sz[_][u] = 1;
  for (int i = 0; i < G[_][u].size(); i++) {
    int v = G[_][u][i];
    dfs(_, v);
    l[_][u] = min(l[_][u], l[_][v]);
    r[_][u] = max(r[_][u], r[_][v]);
    sz[_][u] += sz[_][v];
  }
  int L = l[_][u], R = r[_][u];
  val[_][L][R] = max(val[_][L][R], sz[_][u]);
}
int main() {
  cin >> n;
  for (int _ = 0; _ < 2; _++) {
    cin >> a;
    for (int i = 2; i <= a; i++) {
      int p;
      cin >> p;
      G[_][p].push_back(i);
    }
    for (int i = 1; i <= a; i++) {
      l[_][i] = a + 1;
      r[_][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      cin >> x;
      l[_][x] = r[_][x] = i;
    }
    dfs(_, 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      dp[j] = max(dp[j], dp[i - 1] + max(val[0][i][j], val[1][i][j]));
    }
  }
  cout << dp[n] << endl;
}
