#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int add(int x, int y) {
  x += y;
  if (x >= mod) return x - mod;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) return x + mod;
  return x;
}
int mul(int x, int y) { return (long long)x * y % mod; }
const int MAXN = 2e3 + 5;
int n, n1, n2, dp[MAXN], device[2][MAXN], segment[2][MAXN][MAXN], par[2][MAXN],
    deg[2][MAXN];
void load() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> n1;
  for (int i = 1; i < n1; ++i) {
    int x;
    cin >> x;
    x--;
    par[0][i] = x;
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    x--;
    device[0][i] = x;
  }
  cin >> n2;
  for (int i = 1; i < n2; ++i) {
    int x;
    cin >> x;
    x--;
    par[1][i] = x;
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    x--;
    device[1][i] = x;
  }
}
int main() {
  load();
  for (int id = 0; id < 2; ++id) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < (id == 0 ? n1 : n2); ++j) deg[id][j] = 0;
      for (int j = 1; j < (id == 0 ? n1 : n2); ++j) deg[id][par[id][j]]++;
      int sum = 0;
      for (int j = i; j < n; ++j) {
        for (int x = device[id][j]; x != 0; x = par[id][x]) {
          int parent = par[id][x];
          if (deg[id][parent] > 0) sum++;
          deg[id][parent]--;
          if (deg[id][parent] > 0) break;
        }
        segment[id][i][j] = sum;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    dp[i] = max(segment[0][0][i], segment[1][0][i]);
    for (int j = 0; j < i; ++j)
      dp[i] =
          max(dp[i], dp[j] + max(segment[0][j + 1][i], segment[1][j + 1][i]));
  }
  cout << dp[n - 1];
}
