#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int MAXN = 1e4 + 7;
const int INF = 1e9 + 7;
vector<pair<pair<int, int>, int> > vec;
int sz[MAXN], st[MAXN], ed[MAXN], tg[MAXN];
vector<int> G[MAXN];
void dfs(int u) {
  sz[u] = 1;
  st[u] = INF;
  ed[u] = -INF;
  if (tg[u]) st[u] = ed[u] = tg[u];
  for (auto v : G[u]) {
    dfs(v);
    sz[u] += sz[v];
    st[u] = min(st[u], st[v]);
    ed[u] = max(ed[u], ed[v]);
  }
  vec.push_back(make_pair(make_pair(ed[u], st[u] - 1), sz[u] - (u == 1)));
}
int dp[MAXN];
int main() {
  int n, a, x;
  scanf("%d", &n);
  scanf("%d", &a);
  for (int i = 2; i <= a; i++) {
    scanf("%d", &x);
    G[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    tg[x] = i;
  }
  dfs(1);
  for (int i = 1; i <= a; i++) {
    G[i].clear();
    tg[i] = 0;
  }
  scanf("%d", &a);
  for (int i = 2; i <= a; i++) {
    scanf("%d", &x);
    G[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    tg[x] = i;
  }
  dfs(1);
  sort(vec.begin(), vec.end());
  for (auto it : vec) {
    int l = it.first.second, r = it.first.first;
    dp[r] = max(dp[r], dp[l] + it.second);
  }
  printf("%d", dp[n]);
  return 0;
}
