#include <bits/stdc++.h>
using namespace std;
vector<int> v[2010];
int n, m;
int leaf[2010], sz[2010], dp[2010];
vector<pair<int, int> > ranges[2010];
pair<int, int> dfs(int now) {
  if (now != 1)
    sz[now] = 1;
  else
    sz[now] = 0;
  int minn = 1e9, maxx = 0;
  if (leaf[now]) {
    minn = maxx = leaf[now];
  }
  for (auto i : v[now]) {
    pair<int, int> tmp = dfs(i);
    sz[now] += sz[i];
    minn = min(minn, tmp.first);
    maxx = max(maxx, tmp.second);
  }
  ranges[maxx].emplace_back(make_pair(minn, sz[now]));
  return make_pair(minn, maxx);
}
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= m; j++) v[j].clear();
    memset(leaf, 0, sizeof(leaf));
    scanf("%d", &m);
    int tmp;
    for (int j = 2; j <= m; j++) {
      scanf("%d", &tmp);
      v[tmp].emplace_back(j);
    }
    for (int j = 1; j <= n; j++) {
      scanf("%d", &tmp);
      leaf[tmp] = j;
    }
    dfs(1);
  }
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++)
    for (auto j : ranges[i]) dp[i] = max(dp[i], dp[j.first - 1] + j.second);
  printf("%d\n", dp[n]);
  return 0;
}
