#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 3007;
const int M = 2007;
const int INF = 1e9 + 7;
struct node {
  int d;
  vector<int> g;
} nd[2][N];
int p[2][N], c[2][N];
int dp[M], cost[2][M][M];
int n, a, b;
void calc() {
  for (int l = 1; l <= n; l++) {
    for (int i = 1; i <= a; i++) nd[0][i].d = nd[0][i].g.size();
    int res = 0;
    for (int r = l; r <= n; r++) {
      int v = c[0][r];
      while (v != 1 && !nd[0][v].d) {
        res++;
        nd[0][p[0][v]].d--;
        v = p[0][v];
      }
      cost[0][l][r] = res;
    }
  }
  for (int l = 1; l <= n; l++) {
    for (int i = 1; i <= b; i++) nd[1][i].d = nd[1][i].g.size();
    int res = 0;
    for (int r = l; r <= n; r++) {
      int v = c[1][r];
      while (v != 1 && !nd[1][v].d) {
        res++;
        nd[1][p[1][v]].d--;
        v = p[1][v];
      }
      cost[1][l][r] = res;
    }
  }
}
int main() {
  cin >> n >> a;
  for (int i = 2; i <= a; i++) {
    scanf("%d", &p[0][i]);
    nd[0][p[0][i]].g.push_back(i);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &c[0][i]);
  cin >> b;
  for (int i = 2; i <= b; i++) {
    scanf("%d", &p[1][i]);
    nd[1][p[1][i]].g.push_back(i);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &c[1][i]);
  calc();
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      dp[j] = max(dp[j], dp[i - 1] + max(cost[0][i][j], cost[1][i][j]));
  cout << dp[n];
}
