#include <bits/stdc++.h>
using namespace std;
const int maxn = 2001;
int cost[2][maxn][maxn], n;
void cal(vector<vector<int>> &cost, const vector<int> &p, vector<int> deg,
         const vector<int> &x, int i) {
  for (int l = i; i <= n; ++i) {
    cost[l][i] = cost[l][i - 1];
    int c = x[i];
    while (deg[c] == 1 and c != 1) {
      ++cost[l][i], --deg[p[c]];
      c = p[c];
    }
  }
}
int m[2];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  vector<vector<vector<int>>> cost(
      2, vector<vector<int>>(n + 1, vector<int>(n + 1)));
  for (int v : {0, 1}) {
    cin >> m[v];
    vector<int> p(m[v] + 1), deg(m[v] + 1), x(n + 1);
    for (int j = 2; j <= m[v]; ++j) {
      cin >> p[j];
      ++deg[j], ++deg[p[j]];
    }
    for (int i = 1; i <= n; ++i) {
      cin >> x[i];
    }
    for (int i = 1; i <= n; ++i) cal(cost[v], p, deg, x, i);
  }
  vector<int> dp(n + 1);
  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] << '\n';
}
