#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int fa[2][maxn << 1];
int cost[2][maxn][maxn];
int dd[2][maxn];
int n;
int sz[2];
int dp[maxn];
void init(int t) {
  cin >> sz[t];
  for (int i = (2); i <= (sz[t]); ++i) cin >> fa[t][i];
  for (int i = (1); i <= (n); ++i) cin >> dd[t][i];
}
void cal(int t) {
  for (int l = (1); l <= (n); ++l) {
    vector<int> sons(sz[t] + 1, 0);
    for (int i = (1); i <= (sz[t]); ++i) sons[fa[t][i]]++;
    for (int r = (l); r <= (n); ++r) {
      int now = dd[t][r];
      int val = 0;
      while (now != 1 && sons[now] == 0)
        val++, sons[fa[t][now]]--, now = fa[t][now];
      cost[t][l][r] = cost[t][l][r - 1] + val;
    }
  }
}
void solve() {
  for (int i = (1); i <= (n); ++i) {
    int& ans = dp[i];
    for (int j = (0); j < (i); ++j)
      ans = max(ans, dp[j] + max(cost[1][j + 1][i], cost[0][j + 1][i]));
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = (0); i < (2); ++i) init(i);
  for (int i = (0); i < (2); ++i) cal(i);
  solve();
  cout << dp[n] << endl;
  return 0;
}
