#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int INF = 0x3f3f3f3f, N = 2e6 + 5, MOD = 1e9 + 7;
const long long INF_LL = 0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x, int y) { return (x >> y) & 1; }
template <typename T>
T Smax(T x) {
  return x;
}
template <typename T, typename... Args>
T Smax(T a, Args... args) {
  return max(a, Smax(args...));
}
template <typename T>
T Smin(T x) {
  return x;
}
template <typename T, typename... Args>
T Smin(T a, Args... args) {
  return min(a, Smin(args...));
}
template <typename T>
void errl(istream_iterator<string> it) {}
template <typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  errl(++it, args...);
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " # ";
  err(++it, args...);
}
void Solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  Solve();
  return 0;
}
long long qpow(long long a, long long b, long long MOD) {
  long long res = 1;
  for (; b; b >>= 1, a = a * a % MOD) {
    if (b & 1) res = res * a % MOD;
  }
  return res;
}
int w[2][1005][1005];
int f[N][20], dep[N];
vector<int> G[N];
void addedge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
void build(int x, int _dep, int _fa) {
  f[x][0] = _fa;
  dep[x] = _dep;
  for (int i = 1; i < 20; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  for (auto v : G[x]) {
    if (v == _fa) continue;
    build(v, _dep + 1, x);
  }
}
int getlca(int u, int v) {
  if (dep[u] <= dep[v]) swap(u, v);
  int del = dep[u] - dep[v];
  for (int i = 19; i >= 0; i--)
    if ((1 << i) & del) del -= 1 << i, u = f[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
int mm[N];
int n;
void read(int id) {
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) G[i].clear();
  for (int i = 2; i <= m; i++) {
    int x;
    cin >> x;
    addedge(i, x);
  }
  for (int i = 1; i <= n; i++) {
    cin >> mm[i];
  }
  build(1, 1, 1);
  for (int l = 1; l <= n; l++) {
    for (int r = l; r <= n; r++) {
      int llca, rlca, lca;
      if (l)
        llca = getlca(mm[l - 1], mm[r]);
      else
        llca = 1;
      if (r < n)
        rlca = getlca(mm[r], mm[r + 1]);
      else
        rlca = 1;
      if (dep[llca] < dep[rlca])
        lca = rlca;
      else
        lca = llca;
      w[id][l][r] = w[id][l][r - 1] + dep[mm[r]] - dep[lca];
    }
  }
}
int dp[N];
void Solve() {
  cin >> n;
  read(0);
  read(1);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      dp[j] = max(dp[j], dp[i - 1] + max(w[0][i][j], w[1][i][j]));
    }
  }
  cout << dp[n] << endl;
}
