#include <bits/stdc++.h>
using namespace std;
template <class num>
inline void rd(num &x) {
  char c;
  while (isspace(c = getchar()))
    ;
  bool neg = false;
  if (!isdigit(c))
    neg = (c == '-'), x = 0;
  else
    x = c - '0';
  while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
  if (neg) x = -x;
}
const int N = 3000;
int p[2][N], ent[2][N], sai[2][N], leaf[2][N], l[2][N], sz[2][N], f[2][N],
    pre[2][N][N];
vector<int> t[2][N];
int dfscnt;
void build(int u, int id) {
  sz[id][u] = 1;
  if (t[id][u].empty()) {
    leaf[id][u] = f[id][u];
    ent[id][u] = sai[id][u] = f[id][u];
    return;
  }
  for (auto v : t[id][u]) {
    build(v, id);
    sz[id][u] += sz[id][v];
  }
  sort(begin(t[id][u]), end(t[id][u]),
       [&](int i, int j) { return leaf[id][i] < leaf[id][j]; });
  leaf[id][u] = leaf[id][t[id][u][0]];
  ent[id][u] = ent[id][t[id][u][0]];
  sai[id][u] = sai[id][t[id][u].back()];
}
void dfs(int u, int id) {
  ent[id][u] = dfscnt++;
  for (auto v : t[id][u]) dfs(v, id);
  sai[id][u] = dfscnt - 1;
}
int SIZE[2];
int brute(int id, int u, int l, int r) {
  return pre[id][l][r];
  int cnt = 0;
  for (int i = 1; i <= SIZE[id]; i++)
    if (ent[id][i] >= l and sai[id][i] <= r) cnt++;
  if (cnt == SIZE[id])
    return cnt - 1;
  else
    return cnt;
  if (ent[id][u] > r) return 0;
  if (sai[id][u] < l) return 0;
  if (ent[id][u] >= l and sai[id][u] <= r) return sz[id][u] - (u == 1);
  int ans = 0;
  for (auto v : t[id][u]) ans += brute(id, v, l, r);
  return ans;
}
int remove(int id, int l, int r) {
  int b = brute(id, 1, ent[id][::l[id][l]], ent[id][::l[id][r]]);
  return b;
}
int dp[N][2];
int solve(int p, int t) {
  if (p < 0) return 0;
  int &ans = dp[p][t];
  if (ans != -1) return ans;
  ans = 0;
  for (int i = p; i >= 0; i--)
    ans = max(ans, solve(i - 1, t ^ 1) + remove(t, i, p));
  return ans;
}
int main(void) {
  memset(dp, -1, sizeof dp);
  int leaves;
  rd(leaves);
  int n;
  rd(n);
  for (int i = 2; i <= n; i++) {
    int p;
    rd(p);
    t[0][p].push_back(i);
  }
  for (int i = 0; i < leaves; i++) {
    int x;
    rd(x);
    f[0][x] = i;
    l[0][i] = x;
  }
  build(1, 0);
  int m;
  rd(m);
  for (int i = 2; i <= m; i++) {
    int p;
    rd(p);
    t[1][p].push_back(i);
  }
  for (int i = 0; i < leaves; i++) {
    int x;
    rd(x);
    f[1][x] = i;
    l[1][i] = x;
  }
  build(1, 1);
  SIZE[0] = n;
  SIZE[1] = m;
  for (int id = 0; id <= 1; id++) {
    for (int r = leaves - 1; r >= 0; r--) {
      vector<int> entrada;
      for (int i = 1; i <= SIZE[id]; i++)
        if (sai[id][i] <= r) entrada.push_back(ent[id][i]);
      sort(begin(entrada), end(entrada));
      int total = entrada.size();
      int p = 0;
      for (int l = 0; l <= r; l++) {
        pre[id][l][r] = (total == SIZE[id] ? total - 1 : total);
        while (p < entrada.size() and entrada[p] == l) {
          p++;
          total--;
        }
      }
    }
  }
  cout << max(solve(leaves - 1, 0), solve(leaves - 1, 1)) << endl;
  return 0;
}
