#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e7 + 5;
const int MAXN = 1e4 + 5;
const int INF = 0x3f3f3f3f;
int n, m, s, t, u[MAX], v[MAX], w[MAX], q;
int first[MAXN], nextt[MAX];
int cur[MAXN], cnt = 0, answer = 0, deep[MAXN];
void add(int a, int b, int c) {
  u[cnt] = a, v[cnt] = b, w[cnt] = c;
  nextt[cnt] = first[u[cnt]];
  first[u[cnt]] = cnt;
  ++cnt;
}
bool bfs() {
  deque<int> list1;
  list1.emplace_back(s);
  memset(deep, 0, sizeof(deep));
  deep[s] = 1;
  while (!list1.empty()) {
    int now = list1.front();
    list1.pop_front();
    if (now == t) return true;
    for (int num = first[now]; num != -1; num = nextt[num]) {
      if (!deep[v[num]] && w[num] > 0) {
        deep[v[num]] = deep[now] + 1;
        list1.emplace_back(v[num]);
      }
    }
  }
  return false;
}
int dfs(int now, int limit) {
  if (!limit || now == t) return limit;
  int flow = 0, length = 0;
  for (int &num = cur[now]; num != -1; num = nextt[num]) {
    if (w[num] && deep[v[num]] == deep[now] + 1 &&
        (length = dfs(v[num], min(limit, w[num])))) {
      w[num] -= length;
      w[num ^ 1] += length;
      flow += length;
      limit -= length;
      if (!limit) break;
    }
  }
  if (flow) return flow;
  deep[now] = -1;
  return 0;
}
void dinic() {
  while (bfs()) {
    memcpy(cur, first, sizeof(cur));
    int d = dfs(s, INF);
    if (!d) break;
    answer += d;
  }
}
int A, B;
int p[MAXN], Q[MAXN], x[MAXN], y[MAXN];
int l1[MAXN], r1[MAXN], l2[MAXN], r2[MAXN];
int first1[MAXN], nextt1[MAXN], u1[MAXN], v1[MAXN], cnt1;
int first2[MAXN], nextt2[MAXN], u2[MAXN], v2[MAXN], cnt2;
void add1(int a, int b) {
  u1[cnt1] = a, v1[cnt1] = b;
  nextt1[cnt1] = first1[u1[cnt1]];
  first1[u1[cnt1]] = cnt1;
  ++cnt1;
}
void add2(int a, int b) {
  u2[cnt2] = a, v2[cnt2] = b;
  nextt2[cnt2] = first2[u2[cnt2]];
  first2[u2[cnt2]] = cnt2;
  ++cnt2;
}
void dfs1(int now) {
  bool flag = false;
  for (int num = first1[now]; num != -1; num = nextt1[num]) {
    dfs1(v1[num]);
    flag = true;
    l1[now] = min(l1[now], l1[v1[num]]);
    r1[now] = max(r1[now], r1[v1[num]]);
  }
  if (!flag) l1[now] = r1[now] = x[now];
}
void dfs2(int now) {
  bool flag = false;
  for (int num = first2[now]; num != -1; num = nextt2[num]) {
    dfs2(v2[num]);
    flag = true;
    l2[now] = min(l2[now], l2[v2[num]]);
    r2[now] = max(r2[now], r2[v2[num]]);
  }
  if (!flag) l2[now] = r2[now] = y[now];
}
void solve() {
  cnt1 = cnt2 = 0, cnt = 0, answer = 0;
  memset(first, -1, sizeof(first)), memset(first1, -1, sizeof(first1)),
      memset(first2, -1, sizeof(first2));
  memset(l1, 0x3f, sizeof(l1)), memset(r1, 0, sizeof(r1)),
      memset(l2, 0x3f, sizeof(l2)), memset(r2, 0, sizeof(r2));
  scanf("%d", &n);
  scanf("%d", &A);
  for (int i = 2; i <= A; ++i) scanf("%d", &p[i]), add1(p[i], i);
  for (int i = 1; i <= n; ++i) {
    int num;
    scanf("%d", &num);
    x[num] = i;
  }
  scanf("%d", &B);
  for (int i = 2; i <= B; ++i) scanf("%d", &Q[i]), add2(Q[i], i);
  for (int i = 1; i <= n; ++i) {
    int num;
    scanf("%d", &num);
    y[num] = i;
  }
  dfs1(1);
  dfs2(1);
  s = A + B + 1, t = s + 1;
  for (int i = 2; i <= A; ++i)
    for (int j = 2; j <= B; ++j)
      if (!(r2[j] < l1[i] || r1[i] < l2[j])) add(i, j + A, 1), add(j + A, i, 0);
  for (int i = 2; i <= A; ++i) add(s, i, 1), add(i, s, 0);
  for (int i = 2; i <= B; ++i) add(i + A, t, 1), add(t, i + A, 0);
  dinic();
  int ans = A + B - 2 - answer;
  printf("%d\n", ans);
}
int main(void) {
  solve();
  return 0;
}
