#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int mods[10] = {1000000007, 999999937, 999999929, 999999893, 999999883,
                      999999797,  999999761, 999999757, 999999751, 999999739};
const int mod = 1000000007, mod2 = 998244353;
int rand_mods[2];
const long double eps = 1e-10;
const int siz = 3e3 + 5, siz2 = 3e5 + 5, lg = 20, block = 300, block2 = 1000,
          mxv = 1e5 + 1, sqrt_mod = 31630;
const int alpha_sz = 26;
int n, tsz[2], mn[2][siz], mx[2][siz], par[2][siz],
    remc[2][siz / 3 + 5][siz / 3 + 5], dp[siz / 3 + 5];
vector<int> adj[2][siz];
void dfs(int ii, int node) {
  if (!adj[ii][node].size()) {
    mn[ii][node] = node;
    mx[ii][node] = node;
    return;
  }
  mn[ii][node] = INT_MAX;
  mx[ii][node] = INT_MIN;
  for (int a : adj[ii][node]) {
    dfs(ii, a);
    mn[ii][node] = min(mn[ii][node], mn[ii][a]);
    mx[ii][node] = max(mx[ii][node], mx[ii][a]);
  }
}
int asnd(int ii, int l, int r) {
  int tot = 0, node = r;
  while (mn[ii][node] >= l && mx[ii][node] <= r) {
    tot++;
    node = par[ii][node];
  }
  return tot - 1 - (node == 0);
}
void calcremc(int ii) {
  for (int l = 1; l <= n; l++) {
    remc[ii][l][l] = asnd(ii, l, l);
    for (int r = l + 1; r <= n; r++) {
      remc[ii][l][r] = remc[ii][l][r - 1] + asnd(ii, l, r);
    }
  }
}
void calcdp() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i] = max(dp[i], dp[j - 1] + max(remc[0][j][i], remc[1][j][i]));
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int ii = 0; ii < 2; ii++) {
    scanf("%d", &tsz[ii]);
    for (int i = 2; i <= tsz[ii]; i++) {
      int p;
      scanf("%d", &p);
      adj[ii][p + n].push_back(i + n);
      par[ii][i + n] = p + n;
    }
    for (int i = 1; i <= n; i++) {
      int xv;
      scanf("%d", &xv);
      adj[ii][xv + n].push_back(i);
      par[ii][i] = xv + n;
    }
    dfs(ii, 1 + n);
    calcremc(ii);
  }
  calcdp();
  printf("%d\n", dp[n]);
  return 0;
}
