#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
struct interval {
  int l, r, c;
};
void dfs(int cur, vvec<int>& tree, vec<int>& s, vec<int>& L, vec<int>& R,
         vec<interval>& I) {
  s[cur] = 1;
  for (auto& e : tree[cur]) {
    dfs(e, tree, s, L, R, I);
    s[cur] += s[e];
    L[cur] = min(L[cur], L[e]);
    R[cur] = max(R[cur], R[e]);
  }
  if (cur == 0) s[cur]--;
  I.push_back({L[cur], R[cur], s[cur]});
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A;
  cin >> A;
  vvec<int> treeA(A);
  for (int i = 1; i <= A - 1; i++) {
    int a;
    cin >> a;
    a--;
    treeA[a].push_back(i);
  }
  vec<int> leafA(N);
  for (int i = 0; i < N; i++) {
    cin >> leafA[i];
    leafA[i]--;
  }
  int B;
  cin >> B;
  vvec<int> treeB(B);
  for (int i = 1; i <= B - 1; i++) {
    int b;
    cin >> b;
    b--;
    treeB[b].push_back(i);
  }
  vec<int> leafB(N);
  for (int i = 0; i < N; i++) {
    cin >> leafB[i];
    leafB[i]--;
  }
  vec<interval> I;
  auto calc = [&](vvec<int>& tree, vec<int>& leaf) {
    int n = tree.size();
    vec<int> L(n, 1e9), R(n, 0), s(n, 0);
    for (int i = 0; i < N; i++) L[leaf[i]] = R[leaf[i]] = i;
    dfs(0, tree, s, L, R, I);
  };
  calc(treeA, leafA);
  calc(treeB, leafB);
  vec<int> dp(N + 1, 0);
  vvec<P> C(N);
  for (auto& x : I) {
    C[x.r].push_back({x.l, x.c});
  }
  for (int i = 0; i < N; i++) {
    for (auto& x : C[i]) {
      dp[i + 1] = max(dp[i + 1], dp[x.first] + x.second);
    }
  }
  cout << dp[N] << endl;
}
