#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
vector<int> g[MAXN], g2[MAXN];
vector<pair<pair<int, int>, int>> rng;
vector<pair<int, int>> ss[MAXN];
int dp[MAXN], vis[MAXN], n;
pair<pair<int, int>, int> dfs(int pos, int par, vector<int>* g, int top) {
  if (pos >= top) return {{pos - top, pos - top}, 0};
  pair<int, int> ans = {1e9, -1e9};
  int am = pos > 0;
  for (auto x : g[pos])
    if (x != par) {
      auto xx = dfs(x, pos, g, top);
      ans = {min(ans.first, xx.first.first), max(ans.second, xx.first.second)};
      am += xx.second;
    }
  rng.push_back({ans, am});
  return {ans, am};
}
int solve(int pos) {
  if (pos == n) return 0;
  int& r = dp[pos];
  if (vis[pos]) return r;
  vis[pos] = 1;
  r = -1e9;
  for (auto x : ss[pos]) r = max(r, x.second + solve(x.first + 1));
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int a;
  cin >> a;
  for (int i = 1, ThxDem = a; i < ThxDem; ++i) {
    int x;
    cin >> x;
    x--;
    g[x].push_back(i);
    g[i].push_back(x);
  }
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    int x;
    cin >> x;
    x--;
    g[x].push_back(a + i);
  }
  int b;
  cin >> b;
  for (int i = 1, ThxDem = b; i < ThxDem; ++i) {
    int x;
    cin >> x;
    x--;
    g2[x].push_back(i);
    g2[i].push_back(x);
  }
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    int x;
    cin >> x;
    x--;
    g2[x].push_back(b + i);
  }
  dfs(0, -1, g, a);
  dfs(0, -1, g2, b);
  for (auto x : rng) ss[x.first.first].push_back({x.first.second, x.second});
  memset(dp, -1, sizeof(dp));
  cout << solve(0) << "\n";
}
