#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1024;
int a[N];
int n;
vector<vector<int>> calc_cost(int vn, int n, vector<int> fa, vector<int> tg) {
  vector<vector<int>> res(n + 1, vector<int>(n + 1));
  for (int l = 1; l <= n; ++l) {
    vector<int> deg(vn + 1);
    for (int i = 2; i <= vn; ++i) deg[fa[i]]++;
    int val = 0;
    for (int r = l; r <= n; ++r) {
      for (int v = tg[r]; v != 1 && deg[v] == 0; --deg[v = fa[v]]) {
        val++;
      }
      res[l][r] = val;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> cost[2];
  for (int j = 0; j < 2; ++j) {
    int vn;
    cin >> vn;
    vector<int> fa(vn + 1);
    vector<int> tg(n + 1);
    for (int i = 2; i <= vn; ++i) cin >> fa[i];
    for (int i = 1; i <= n; ++i) cin >> tg[i];
    cost[j] = calc_cost(vn, n, fa, tg);
  }
  vector<int> dp(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < i; ++j)
      dp[i] = max(dp[i], dp[j] + max(cost[0][j + 1][i], cost[1][j + 1][i]));
  }
  cout << dp[n];
  return 0;
}
