#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int l[maxn], r[maxn];
int siz[maxn];
int dp[maxn];
struct node {
  int l, r, w;
};
vector<node> v;
bool cmp(node x, node y) { return x.r < y.r; }
vector<int> E[maxn];
void dfs(int x, int fa) {
  siz[x] = 1;
  for (auto i : E[x]) {
    if (i == fa) continue;
    dfs(i, x);
    siz[x] += siz[i];
    l[x] = min(l[x], l[i]);
    r[x] = max(r[x], r[i]);
  }
  v.push_back((node){l[x], r[x], siz[x] - (x == 1)});
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a, b;
  cin >> a;
  for (int i = 1; i <= a; i++) l[i] = 0x3f3f3f3f;
  for (int i = 2; i <= a; i++) {
    int x;
    cin >> x;
    E[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    l[x] = r[x] = i;
  }
  dfs(1, 1);
  cin >> b;
  for (int i = 1; i <= b; i++) l[i] = 0x3f3f3f3f, r[i] = 0, E[i].clear();
  for (int i = 2; i <= b; i++) {
    int x;
    cin >> x;
    E[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    l[x] = r[x] = i;
  }
  dfs(1, 1);
  sort(v.begin(), v.end(), cmp);
  for (int i = 1; i < maxn; i++) dp[i] = -1e9;
  for (auto i : v) {
    dp[i.r] = max(dp[i.r], dp[i.l - 1] + i.w);
  }
  int res = 0;
  for (int i = 0; i < maxn; i++) res = max(res, dp[i]);
  cout << res << endl;
}
