#include <bits/stdc++.h>
using namespace std;
int dp[2][1002];
int ndp[2][1002];
int main() {
  int n;
  scanf("%d", &n);
  int A, B;
  scanf("%d", &A);
  vector<int> pA(A, -1), dA(n);
  for (int i = 1; i < A; i++) {
    scanf("%d", &pA[i]);
    pA[i]--;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &dA[i]);
    dA[i]--;
  }
  scanf("%d", &B);
  vector<int> pB(B, -1), dB(n);
  for (int i = 1; i < B; i++) {
    scanf("%d", &pB[i]);
    pB[i]--;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &dB[i]);
    dB[i]--;
  }
  vector<vector<int>> aPath;
  for (int i = 0; i < A; i++) {
    vector<int> cur;
    int p = i;
    while (p != 0) {
      cur.push_back(p);
      p = pA[p];
    }
    aPath.emplace_back(cur);
  }
  vector<vector<int>> bPath;
  for (int i = 0; i < B; i++) {
    vector<int> cur;
    int p = i;
    while (p != 0) {
      cur.push_back(p);
      p = pB[p];
    }
    bPath.emplace_back(cur);
  }
  for (int i = 0; i < n; i++) {
    set<int> sideAcache, sideBcache;
    sideAcache.insert(aPath[dA[i]].begin(), aPath[dA[i]].end());
    sideBcache.insert(bPath[dB[i]].begin(), bPath[dB[i]].end());
    for (int side = 0; side < 2; side++)
      fill(ndp[side], ndp[side] + 1002, INT_MAX / 2);
    for (int side = 0; side < 2; side++) {
      int same_cost = 0;
      if (side == 0) {
        same_cost = sideAcache.size();
      } else {
        same_cost = sideBcache.size();
      }
      if (i > 0) {
        if (side == 0) {
          for (auto p : aPath[dA[i - 1]])
            if (sideAcache.count(p)) same_cost--;
        } else {
          for (auto p : bPath[dB[i - 1]])
            if (sideBcache.count(p)) same_cost--;
        }
      }
      for (int j = 0; j <= i; j++) {
        int last_other = j - 1;
        int base = dp[side][j];
        if (base >= INT_MAX / 2) continue;
        { ndp[side][j] = min(ndp[side][j], base + same_cost); }
        {
          int diff_cost = (side == 0) ? sideBcache.size() : sideAcache.size();
          if (last_other >= 0) {
            if (side == 0) {
              int bans = bPath[dB[last_other]].size();
              int low = 0, high = bans - 1;
              while (low <= high) {
                int mid = (low + high) >> 1;
                if (sideBcache.count(bPath[dB[last_other]][mid])) {
                  bans = mid;
                  high = mid - 1;
                } else {
                  low = mid + 1;
                }
              }
              diff_cost -= (int)bPath[dB[last_other]].size() - bans;
            } else {
              int bans = aPath[dA[last_other]].size();
              int low = 0, high = bans - 1;
              while (low <= high) {
                int mid = (low + high) >> 1;
                if (sideAcache.count(aPath[dA[last_other]][mid])) {
                  bans = mid;
                  high = mid - 1;
                } else {
                  low = mid + 1;
                }
              }
              diff_cost -= (int)aPath[dA[last_other]].size() - bans;
            }
          }
          ndp[side ^ 1][i] = min(ndp[side ^ 1][i], base + diff_cost);
        }
      }
    }
    memcpy(dp, ndp, sizeof(dp));
  }
  int ans = min(*min_element(ndp[0], ndp[0] + 1002),
                *min_element(ndp[1], ndp[1] + 1002));
  ans = A + B - ans - 2;
  printf("%d\n", ans);
  return 0;
}
