#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
int a;
const int maxN = 2005;
int p[2][maxN];
vector<int> g[2][maxN];
int cnt[2];
int x[2][maxN];
int ord[2][maxN];
vector<pair<int, int> > segs[2][maxN];
int dp[maxN];
int l[2][maxN], r[2][maxN];
int sz[2][maxN];
void dfs(int v, int id) {
  sz[id][v] = 1;
  if (ord[id][v] != 0) {
    l[id][v] = r[id][v] = ord[id][v];
    segs[id][r[id][v]].emplace_back(l[id][v], sz[id][v]);
    return;
  }
  int mn = maxN * 5;
  int mx = -maxN * 5;
  for (int to : g[id][v]) {
    dfs(to, id);
    mn = min(mn, l[id][to]);
    mx = max(mx, r[id][to]);
    sz[id][v] += sz[id][to];
  }
  l[id][v] = mn;
  r[id][v] = mx;
  segs[id][r[id][v]].emplace_back(l[id][v], sz[id][v] - (v == 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < 2; i++) {
    cin >> cnt[i];
    for (int j = 1; j < cnt[i]; j++) {
      cin >> p[i][j];
      g[i][p[i][j]].push_back(j + 1);
    }
    for (int j = 1; j <= n; j++) {
      cin >> x[i][j];
      ord[i][x[i][j]] = j;
    }
  }
  dfs(1, 0);
  dfs(1, 1);
  for (int l = 1; l <= n; l++) {
    dp[l] = max(dp[l], dp[l - 1]);
    for (auto &it : segs[0][l]) {
      dp[l] = max(dp[l], dp[it.first - 1] + it.second);
    }
    for (auto &it : segs[1][l]) {
      dp[l] = max(dp[l], dp[it.first - 1] + it.second);
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
