#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
const long long MAXN = 2e5;
vector<pair<long long, long long> > L[MAXN];
vector<pair<long long, long long> > sv[MAXN];
stack<pair<long long, long long> > st[2];
long long lca[MAXN][2];
long long arr[MAXN][2];
long long D[MAXN][2];
long long dp[MAXN][2];
long long order[MAXN][2];
long long acum[2];
long long N;
long long A, B;
long long maynode;
long long dist;
long long pos;
void sorting() {
  for (long long i = 0; i < MAXN; i++) {
    for (auto x : L[i]) {
      sv[x.second].push_back({i, x.first});
    }
    L[i].clear();
  }
  for (long long i = 0; i < MAXN; i++) {
    for (auto x : sv[i]) {
      L[x.first].push_back({x.second, i});
    }
  }
}
long long DFS(long long node, long long mod) {
  long long me = oo;
  long long cont = 0;
  for (long long i = 0; i < L[node].size(); i++) {
    D[L[node][i].first][mod] = D[node][mod] + 1;
    L[node][i].second = DFS(L[node][i].first, mod);
    me = min(me, L[node][i].second);
    cont++;
  }
  if (!cont) return order[node][mod];
  return me;
}
void DFS2(long long node, long long mod) {
  long long cont = 0;
  for (auto v : L[node]) {
    if (D[node][mod] < dist) {
      dist = D[node][mod];
      maynode = node;
    }
    DFS2(v.first, mod);
    cont++;
    if (D[node][mod] < dist) {
      dist = D[node][mod];
      maynode = node;
    }
  }
  if (!cont) {
    lca[pos][mod] = maynode;
    dist = oo;
    pos++;
  }
}
struct monotonic_stack {
  stack<pair<long long, long long> > st;
  long long sz = 0;
  void insert(long long x) {
    ++sz;
    if (!st.size())
      st.push({x, sz});
    else if (st.size() && x < st.top().first)
      st.push({x, sz});
  }
  long long minimun() {
    if (!sz) return oo;
    return st.top().first;
  }
  void del() {
    if (!sz) return;
    --sz;
    if (st.size() && st.top().second > sz) st.pop();
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 0; i < MAXN; i++) {
    dp[i][0] = dp[i][1] = oo;
  }
  cin >> N;
  cin >> A;
  for (long long i = 2; i <= A; i++) {
    long long p;
    cin >> p;
    L[p].push_back({i, 0});
  }
  for (long long i = 1; i <= N; i++) {
    cin >> arr[i][0];
    order[arr[i][0]][0] = i;
  }
  DFS(1, 0);
  sorting();
  maynode = -1;
  dist = oo;
  pos = 0;
  DFS2(1, 0);
  for (long long i = 0; i < MAXN; i++) L[i].clear(), sv[i].clear();
  cin >> B;
  for (long long i = 2; i <= B; i++) {
    long long p;
    cin >> p;
    L[p].push_back({i, 0});
  }
  for (long long i = 1; i <= N; i++) {
    cin >> arr[i][1];
    order[arr[i][1]][1] = i;
  }
  DFS(1, 1);
  sorting();
  maynode = -1;
  dist = oo;
  pos = 0;
  DFS2(1, 1);
  dp[1][0] = dp[1][1] = 0;
  acum[0] = D[arr[1][0]][0];
  acum[1] = D[arr[1][1]][1];
  monotonic_stack mts[2];
  st[0].push({dp[1][0], 0});
  st[1].push({dp[1][1], 0});
  mts[0].insert(dp[1][0]);
  mts[1].insert(dp[1][1]);
  for (long long i = 2; i <= N; i++) {
    for (long long x = 0, y = 1; x <= 1; x++, y--) {
      dp[i][x] = mts[y].minimun() + acum[y] - acum[x] + D[lca[i - 1][x]][x];
    }
    for (long long x = 0, y = 1; x <= 1; x++, y--) {
      if (i == N) break;
      st[x].push({dp[i][x], D[lca[i - 1][y]][y]});
      mts[x].insert(dp[i][x] - D[lca[i - 1][y]][y]);
      long long depth = D[lca[i][y]][y];
      long long me = oo;
      long long cont = 0;
      while (st[x].size() && st[x].top().second >= depth) {
        me = min(me, st[x].top().first);
        st[x].pop();
        mts[x].del();
        cont++;
      }
      if (me != oo) {
        st[x].push({me, depth});
        mts[x].insert(me - depth);
      }
    }
    acum[0] += D[arr[i][0]][0] - D[lca[i - 1][0]][0];
    acum[1] += D[arr[i][1]][1] - D[lca[i - 1][1]][1];
  }
  long long res = oo;
  for (long long i = 1; i <= N; i++) {
    res = min(res, min(dp[i][0] + acum[0], dp[i][1] + acum[1]));
  }
  cout << A + B - 2 - res << '\n';
  return 0;
}
