#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 5;
int n;
vector<int> edge[2][maxn];
int l[2][maxn], r[2][maxn], siz[2][maxn], val[2][1005][1005];
int dp[maxn];
void dfs(int N, int x) {
  if (x != 1) siz[N][x] = 1;
  for (int i = 0; i < edge[N][x].size(); i++) {
    int v = edge[N][x][i];
    dfs(N, v);
    l[N][x] = min(l[N][x], l[N][v]);
    r[N][x] = max(r[N][x], r[N][v]);
    siz[N][x] += siz[N][v];
  }
  val[N][l[N][x]][r[N][x]] = max(val[N][l[N][x]][r[N][x]], siz[N][x]);
}
int main() {
  cin >> n;
  for (int N = 0; N < 2; N++) {
    int a;
    cin >> a;
    for (int i = 1; i <= a; i++) {
      l[N][i] = n + 1;
      r[N][i] = 0;
    }
    for (int i = 2; i <= a; i++) {
      int x;
      cin >> x;
      edge[N][x].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      l[N][x] = r[N][x] = i;
    }
    dfs(N, 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i] = max(dp[i], dp[j - 1] + max(val[0][j][i], val[1][j][i]));
    }
  }
  cout << dp[n] << "\n";
}
