#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 888;
vector<int> G[2][maxn];
int val[2][1111][1111];
int l[maxn], r[maxn];
int siz[maxn];
void dfs(int s, int fa, int id) {
  if (s != 1)
    siz[s] = 1;
  else
    siz[s] = 0;
  for (int d : G[id][s]) {
    if (d == fa) continue;
    dfs(d, s, id);
    siz[s] += siz[d];
    l[s] = min(l[s], l[d]);
    r[s] = max(r[s], r[d]);
  }
  val[id][l[s]][r[s]] = siz[s];
}
int dp[maxn];
void solve() {
  int nn;
  scanf("%d", &nn);
  memset(val, 128, sizeof(val));
  int tot = 0;
  for (int t = 0; t <= 1; t++) {
    int n;
    scanf("%d", &n);
    tot += n - 1;
    for (int i = 2; i <= n; i++) {
      int f;
      scanf("%d", &f);
      G[t][f].push_back(i);
    }
    memset(l, 0x3f, sizeof(l));
    memset(r, 128, sizeof(r));
    for (int i = 1; i <= nn; i++) {
      int a;
      scanf("%d", &a);
      l[a] = i;
      r[a] = i;
    }
    dfs(1, 1, t);
  }
  for (int i = 1; i <= nn; i++) {
    for (int cut = 0; cut < i; cut++) {
      dp[i] = max(dp[i], dp[cut] + max(val[0][cut + 1][i], val[1][cut + 1][i]));
    }
  }
  cout << dp[nn] << endl;
}
signed main() { solve(); }
