#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, val;
} A[2010], B[2010];
vector<int> Ga[2010];
vector<int> Gb[2010];
vector<pair<long long, long long> > alt[2010];
void solve(int cur, vector<int> *G, node *nodes) {
  if (G[cur].empty()) {
    alt[nodes[cur].r].push_back({nodes[cur].l, nodes[cur].val});
    return;
  }
  bool flag = true;
  for (auto nx : G[cur]) {
    solve(nx, G, nodes);
    if (flag) {
      nodes[cur] = {nodes[nx].l, nodes[nx].r, nodes[nx].val + 1};
      flag = false;
    } else {
      nodes[cur].l = min(nodes[cur].l, nodes[nx].l);
      nodes[cur].r = max(nodes[cur].r, nodes[nx].r);
      nodes[cur].val += nodes[nx].val;
    }
  }
  if (cur == 0) {
    nodes[cur].val--;
  }
  alt[nodes[cur].r].push_back({nodes[cur].l, nodes[cur].val});
}
long long mem[2010];
long long getAns(long long pos) {
  if (pos < 0) return 0;
  if (mem[pos] != -1) return mem[pos];
  long long res = 0;
  for (auto pa : alt[pos]) {
    res = max(res, getAns(pa.first - 1) + pa.second);
  }
  res = max(res, getAns(pos - 1));
  mem[pos] = res;
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, a, b;
  cin >> n >> a;
  for (int i = 0; i < a - 1; i++) {
    int u;
    cin >> u;
    u--;
    Ga[u].push_back(i + 1);
  }
  for (int i = 0; i < n; i++) {
    int u;
    cin >> u;
    u--;
    A[u].l = i;
    A[u].r = i;
    A[u].val = 1;
  }
  cin >> b;
  for (int i = 0; i < b - 1; i++) {
    int u;
    cin >> u;
    u--;
    Gb[u].push_back(i + 1);
  }
  for (int i = 0; i < n; i++) {
    int u;
    cin >> u;
    u--;
    B[u].l = i;
    B[u].r = i;
    B[u].val = 1;
  }
  solve(0, Ga, A);
  solve(0, Gb, B);
  for (long long i = 0; i < 2010; i++) mem[i] = -1;
  cout << getAns(n + 4) << endl;
  return 0;
}
