#include <bits/stdc++.h>
using namespace std;
vector<int> L[2][2000 + 1];
pair<int, int> range[2][2000 + 1];
int dp[2000 + 1][2000 + 1];
int idx[2][2000 + 1];
int sz[2][2000 + 1];
int best[2000 + 1];
int N, A, B;
void DFS(int l, int node) {
  sz[l][node] = (node != 1);
  if (L[l][node].size() == 0) {
    range[l][node] = {idx[l][node], idx[l][node]};
  } else {
    for (auto child : L[l][node]) {
      DFS(l, child);
      sz[l][node] += sz[l][child];
      range[l][node].first = min(range[l][node].first, range[l][child].first);
      range[l][node].second =
          max(range[l][node].second, range[l][child].second);
    }
  }
  dp[range[l][node].first][range[l][node].second] =
      max(dp[range[l][node].first][range[l][node].second], sz[l][node]);
}
int main() {
  int i, j, node, res;
  cin >> N;
  cin >> A;
  for (i = 2; i <= A; i++) cin >> node, L[0][node].push_back(i);
  for (i = 1; i <= N; i++) cin >> node, idx[0][node] = i;
  cin >> B;
  for (i = 2; i <= B; i++) cin >> node, L[1][node].push_back(i);
  for (i = 1; i <= N; i++) cin >> node, idx[1][node] = i;
  for (i = 1; i <= max(A, B); i++)
    range[0][i] = range[1][i] = {(N + 1), -(N + 1)};
  DFS(0, 1);
  DFS(1, 1);
  res = max(A - 1, B - 1);
  for (i = 1; i <= N; i++)
    for (j = i; j <= N; j++) best[j] = max(best[j], best[i - 1] + dp[i][j]);
  res = max(res, best[N]);
  cout << res;
  return 0;
}
