#include <bits/stdc++.h>
using namespace std;
void OUT_TST(string s, istream_iterator<string> it) { cerr << s; }
template <typename T, typename... Args>
void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " ";
  OUT_TST(s, ++it, args...);
}
template <class T>
void rd(T& ret) {
  ret = 0;
  bool ok = 0, u = 0;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + (ret << 1) + c - '0', ok = 1;
    else if (c == '-')
      u = 1;
    else if (ok) {
      if (u) ret *= -1;
      return;
    }
  }
}
long long powmod(long long p, long long n, long long mod) {
  long long ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
  }
  return ret;
}
template <class T>
bool chmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int INF = (int)1e8;
void input(vector<vector<int>>& son, vector<int>& an, vector<int>& sz, int n) {
  int m;
  cin >> m;
  son.resize(m);
  an.resize(m, -1);
  sz.resize(m, 0);
  for (int i = 0; i < m - 1; ++i) {
    int t;
    cin >> t;
    --t;
    son[t].push_back(i + 1);
  }
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    --t;
    an[t] = i;
  }
}
pair<int, int> dfs(int first, const vector<vector<int>>& son,
                   const vector<int>& idx, vector<vector<pair<int, int>>>& cost,
                   vector<int>& sz) {
  sz[first] = 1;
  if (idx[first] != -1) {
    cost[idx[first]].emplace_back(idx[first], 1);
    return {idx[first], idx[first]};
  }
  int mi = INF, mx = -INF;
  pair<int, int> tmp;
  for (int second : son[first]) {
    tmp = dfs(second, son, idx, cost, sz);
    sz[first] += sz[second];
    chmin(mi, tmp.first);
    chmax(mx, tmp.second);
  }
  int c = sz[first];
  if (first == 0) --c;
  cost[mi].emplace_back(mx, c);
  return {mi, mx};
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> an, bn, sza, szb;
  vector<vector<int>> sa, sb;
  input(sa, an, sza, n);
  input(sb, bn, szb, n);
  vector<vector<pair<int, int>>> cost(n);
  auto tmp = dfs(0, sa, an, cost, sza);
  assert(tmp.first == 0 && tmp.second == n - 1);
  tmp = dfs(0, sb, bn, cost, szb);
  assert(tmp.first == 0 && tmp.second == n - 1);
  vector<int> dp(n + 1, 0);
  for (auto& i : cost[0]) {
    chmax(dp[i.first], i.second);
  }
  for (int i = 0; i < n - 1; ++i) {
    chmax(dp[i + 1], dp[i]);
    for (auto& j : cost[i + 1]) {
      chmax(dp[j.first], dp[i] + j.second);
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
