#include <bits/stdc++.h>
using namespace std;
const double long EPS = 1e-7;
vector<vector<long long>> precost(long long n, vector<long long> &p,
                                  vector<long long> &id) {
  vector<vector<long long>> res(n, vector<long long>(n));
  for (int i = 0; i < n; i++) {
    vector<long long> deg(p.size());
    for (int j = 1; j < p.size(); j++) {
      deg[p[j]]++;
    }
    long long val = 0;
    for (int j = i; j < n; j++) {
      long long cur = id[j];
      while (cur != 0 && deg[cur] == 0) {
        val++;
        deg[p[cur]]--;
        cur = p[cur];
      }
      res[i][j] = val;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<vector<long long>> adj(2);
  vector<vector<long long>> id(2, vector<long long>(n));
  for (int i = 0; i < 2; i++) {
    long long a;
    cin >> a;
    adj[i].resize(a);
    for (int j = 1; j <= a - 1; j++) {
      cin >> adj[i][j];
      adj[i][j]--;
    }
    for (int j = 0; j < n; j++) {
      cin >> id[i][j];
      id[i][j]--;
    }
  }
  vector<vector<vector<long long>>> cost(2);
  for (int i = 0; i < 2; i++) {
    cost[i] = precost(n, adj[i], id[i]);
  }
  vector<long long> dp(n + 1);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dp[j] = max(dp[j], dp[i] + max(cost[0][i][j - 1], cost[1][i][j - 1]));
    }
  }
  cout << dp[n];
  return 0;
}
