#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 2505;
bool ok[3][N][N];
vector<int> g[3][N];
int n, a, x[N], b, y[N], dp[N], sz[N][3], pos[N][3], mn[N][3], mx[N][3],
    val[3][N][N];
void dfs(int v, int tp) {
  if (pos[v][tp]) {
    mn[v][tp] = mx[v][tp] = pos[v][tp];
    ok[tp][mn[v][tp]][mx[v][tp]] = 1;
    val[tp][mn[v][tp]][mx[v][tp]] = sz[v][tp] + (v != 1);
    return;
  }
  mn[v][tp] = N * N;
  for (auto to : g[tp][v]) {
    dfs(to, tp);
    mn[v][tp] = min(mn[v][tp], mn[to][tp]);
    mx[v][tp] = max(mx[v][tp], mx[to][tp]);
    sz[v][tp] += sz[to][tp] + 1;
  }
  ok[tp][mn[v][tp]][mx[v][tp]] = 1;
  val[tp][mn[v][tp]][mx[v][tp]] = sz[v][tp] + (v != 1);
}
int main() {
  cin >> n;
  cin >> a;
  for (int i = 2; i <= a; i++) {
    int p;
    cin >> p;
    g[1][p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    pos[x[i]][1] = i;
  }
  cin >> b;
  for (int i = 2; i <= b; i++) {
    int p;
    cin >> p;
    g[2][p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> y[i];
    pos[y[i]][2] = i;
  }
  dfs(1, 1);
  dfs(1, 2);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dp[j - 1] == -1) continue;
      for (int x = 1; x <= 2; x++)
        if (ok[x][j][i]) dp[i] = max(dp[i], dp[j - 1] + val[x][j][i]);
    }
  }
  cout << dp[n];
  return 0;
}
