#include <bits/stdc++.h>
using namespace std;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(long long x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(long double x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T>
void pr(const T& x);
template <class T, class... Ts>
void pr(const T& t, const Ts&... ts) {
  pr(t);
  pr(ts...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T>
void pr(const T& x) {
  pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
  pr("}");
}
void ps() { pr("\n"); }
template <class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(" ");
  ps(ts...);
}
void pc() { cout << "]" << endl; }
template <class T, class... Ts>
void pc(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(", ");
  pc(ts...);
}
}  // namespace output
using namespace output;
const int MX = 1005;
int n, a, b;
vector<int> adj[2 * MX][2];
int leaf[MX][2];
int pos[2 * MX][2];
int siz[2 * MX][2];
int best[MX][MX][2];
int ans[MX][2];
pair<int, int> rang[2 * MX][2];
void dfs(int v, int p, int d) {
  if (pos[v][d] != -1) rang[v][d] = {pos[v][d], pos[v][d]};
  siz[v][d] = 1;
  for (int to : adj[v][d]) {
    if (to != p) {
      dfs(to, v, d);
      siz[v][d] += siz[to][d];
      rang[v][d].first = min(rang[v][d].first, rang[to][d].first);
      rang[v][d].second = max(rang[v][d].second, rang[to][d].second);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> a;
  for (int i = 0; i < a; i++) pos[i][0] = -1, rang[i][0] = {1e9, -1e9};
  for (int i = 0; i < a - 1; i++) {
    int p;
    cin >> p;
    adj[p - 1][0].push_back(i + 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> leaf[i][0], leaf[i][0]--;
    pos[leaf[i][0]][0] = i;
  }
  cin >> b;
  for (int i = 0; i < b; i++) pos[i][1] = -1, rang[i][1] = {1e9, -1e9};
  for (int i = 0; i < b - 1; i++) {
    int p;
    cin >> p;
    adj[p - 1][1].push_back(i + 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> leaf[i][1], leaf[i][1]--;
    pos[leaf[i][1]][1] = i;
  }
  dfs(0, -1, 0);
  dfs(0, -1, 1);
  for (int i = 0; i < a; i++) {
    auto cur = rang[i][0];
    best[cur.first][cur.second][0] =
        max(best[cur.first][cur.second][0], siz[i][0] - (i == 0));
  }
  for (int i = 0; i < b; i++) {
    auto cur = rang[i][1];
    best[cur.first][cur.second][1] =
        max(best[cur.first][cur.second][1], siz[i][1] - (i == 0));
  }
  for (int c = 0; c < 2; c++) {
    for (int len = 2; len < n + 1; len++) {
      for (int st = 0; st < n; st++) {
        if (st + len - 1 < n) {
          int l = st, r = st + len - 1;
          for (int k = l; k < r + 1; k++) {
            if (k < r)
              best[l][r][c] =
                  max(best[l][r][c], best[l][k][c] + best[k + 1][r][c]);
          }
        }
      }
    }
  }
  for (int i = 0; i < n + 1; i++) ans[i][0] = -1e9, ans[i][1] = -1e9;
  ans[0][0] = 0, ans[0][1] = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < i; j++) {
      ans[i][0] = max(ans[i][0], ans[j][1] + best[j][i - 1][1]);
      ans[i][1] = max(ans[i][1], ans[j][0] + best[j][i - 1][0]);
    }
  }
  cout << max(ans[n][0], ans[n][1]) << '\n';
}
