#include <bits/stdc++.h>
using namespace std;
const int kN = 1 << 11;
int sz[2], par[2][kN], deg[2][kN], used_deg[kN], node[2][kN], cost[kN][kN],
    dp[kN];
int main() {
  int n;
  cin >> n;
  cin >> sz[0];
  for (int i = 2; i <= sz[0]; i++) {
    cin >> par[0][i];
    ++deg[0][par[0][i]];
  }
  for (int i = 1; i <= n; i++) cin >> node[0][i];
  cin >> sz[1];
  for (int i = 2; i <= sz[1]; i++) {
    cin >> par[1][i];
    ++deg[1][par[1][i]];
  }
  for (int i = 1; i <= n; i++) cin >> node[1][i];
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= n; j++) {
      memset(used_deg, 0, sizeof(used_deg));
      int val = 0;
      for (int k = j; k <= n; k++) {
        int x = node[i][k];
        while (par[i][x] && used_deg[x] + 1 >= deg[i][x]) {
          ++used_deg[x];
          ++val;
          x = par[i][x];
        }
        ++used_deg[x];
        cost[j][k] = max(cost[j][k], val);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i] = max(dp[i], dp[j - 1] + cost[j][i]);
    }
  }
  cout << dp[n] << '\n';
}
