#include <bits/stdc++.h>
using namespace std;
namespace Fread {
const int MAXN = 1 << 20;
char buf[MAXN], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, MAXN, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
inline int read() {
  int f = 1, x = 0;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = Fread::getchar();
  }
  return x * f;
}
inline long long readll() {
  long long f = 1, x = 0;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = Fread::getchar();
  }
  return x * f;
}
const int MAXN = 1000;
int m;
struct Tree {
  int n, fa[MAXN * 2 + 5], id[MAXN * 2 + 5];
  void input() {
    n = read();
    for (int i = 2; i <= n; ++i) fa[i] = read();
    for (int i = 1; i <= m; ++i) id[i] = read();
  }
} T1, T2;
int f1[MAXN + 5][MAXN + 5], f2[MAXN + 5][MAXN + 5];
void calc_f(const Tree &T, int f[MAXN + 5][MAXN + 5]) {
  static int d[MAXN * 2 + 5];
  for (int l = 1; l <= m; ++l) {
    for (int i = 1; i <= T.n; ++i) d[i] = 0;
    for (int i = 2; i <= T.n; ++i) d[T.fa[i]]++;
    for (int r = l; r <= m; ++r) {
      f[l][r] = f[l][r - 1];
      int u = T.id[r];
      while (u != 1 && !d[u]) {
        f[l][r]++;
        d[T.fa[u]]--;
        u = T.fa[u];
      }
    }
  }
}
int dp[MAXN + 5];
int main() {
  m = read();
  T1.input();
  calc_f(T1, f1);
  T2.input();
  calc_f(T2, f2);
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j <= i - 1; ++j) {
      dp[i] = max(dp[i], dp[j] + max(f1[j + 1][i], f2[j + 1][i]));
    }
  }
  cout << dp[m] << endl;
  return 0;
}
