#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  int solve(int n, vector<int>& PA, vector<int>& PB, vector<int>& A,
            vector<int>& B) {
    init(PA, A, graphA, depthsA, sizesA, minsA, maxsA, leavesA, parsA);
    init(PB, B, graphB, depthsB, sizesB, minsB, maxsB, leavesB, parsB);
    buildLCA(B, parsB, depthsB, rangeLCA, sumPath);
    vector<int> ord;
    dfs2(0, graphA, ord);
    int res = max(PA.size(), PB.size());
    const int total = PA.size() + PB.size();
    const int MAX = total + 1000;
    int N = PA.size() + 1;
    vector<int> nexts(N, 0);
    vector<vector<int>> dp(N, vector<int>(n + 1, MAX));
    dp[0][0] = 0;
    vector<int> pre(n + 1, MAX);
    pre[0] = 0;
    for (auto u : ord) {
      int l = minsA[u], r = maxsA[u];
      int p = rangeLCA[l][r];
      int sum = sumPath[l][r];
      if (nexts[u] < graphA[u].size()) {
        int v = graphA[u][nexts[u]++];
        for (int i = 0; i <= n; ++i) {
          dp[v][i] = min(dp[v][i], pre[i] += 1);
        }
      } else if (nexts[u] == graphA[u].size()) {
        auto pdp = dp[u];
        dp[u] = pre;
        for (int i = 0; i <= l; ++i) {
          int sum1 = sum;
          if (i > 0) {
            int pp = lca(B[i - 1], B[l], depthsB, parsB);
            sum1 -= depthsB[pp];
          }
          dp[u][r + 1] = min(dp[u][r + 1], pdp[i] + sum1 - (u == 0 ? 0 : 1));
        }
        pre = dp[u];
      } else {
        continue;
      }
    }
    for (int i = 0; i <= n; ++i) {
      res = max(res, total - dp[0][i]);
    }
    return res;
  }

 private:
  vector<vector<int>> graphA;
  vector<vector<int>> graphB;
  vector<vector<int>> parsA;
  vector<vector<int>> parsB;
  vector<int> depthsA;
  vector<int> depthsB;
  vector<int> sizesA;
  vector<int> sizesB;
  vector<int> minsA;
  vector<int> minsB;
  vector<int> maxsA;
  vector<int> maxsB;
  vector<int> leavesA;
  vector<int> leavesB;
  vector<vector<int>> rangeLCA;
  vector<vector<int>> sumPath;
  vector<vector<int>> costA;
  vector<vector<int>> costB;
  void init(vector<int>& P, vector<int>& L, vector<vector<int>>& graph,
            vector<int>& depths, vector<int>& sizes, vector<int>& mins,
            vector<int>& maxs, vector<int>& leaves, vector<vector<int>>& pars) {
    int n = P.size() + 1;
    graph.clear();
    graph.resize(n);
    depths.clear();
    depths.resize(n, 0);
    sizes.clear();
    sizes.resize(n, 0);
    mins.clear();
    mins.resize(n, n + 10000);
    maxs.clear();
    maxs.resize(n, -1);
    leaves.clear();
    leaves.resize(n, -1);
    pars.clear();
    int h = 0;
    while (1 << h < n) {
      ++h;
    }
    pars.resize(n, vector<int>(h + 1, -1));
    for (int i = 0; i < L.size(); ++i) {
      leaves[L[i]] = i;
    }
    for (int i = 0; i < P.size(); ++i) {
      int p = P[i];
      int v = i + 1;
      graph[p].push_back(v);
    }
    int rt = 0;
    dfs(rt, -1, 0, graph, depths, sizes, mins, maxs, leaves, pars);
    auto cmp = [&](int l, int r) {
      if (depths[l] == depths[r]) {
        return mins[l] < mins[r];
      }
      return depths[l] < depths[r];
    };
    for (auto& V : graph) {
      sort(V.begin(), V.end(), cmp);
    }
  }
  void dfs(int u, int p, int d, vector<vector<int>>& graph, vector<int>& depths,
           vector<int>& sizes, vector<int>& mins, vector<int>& maxs,
           vector<int>& leaves, vector<vector<int>>& pars) {
    depths[u] = d;
    pars[u][0] = p;
    sizes[u] = 1;
    for (int i = 1; i < pars[u].size(); ++i) {
      if (pars[u][i - 1] == -1) {
        break;
      }
      pars[u][i] = pars[pars[u][i - 1]][i - 1];
    }
    if (leaves[u] != -1) {
      assert(graph[u].empty());
      maxs[u] = mins[u] = leaves[u];
    }
    for (auto v : graph[u]) {
      dfs(v, u, d + 1, graph, depths, sizes, mins, maxs, leaves, pars);
      maxs[u] = max(maxs[u], maxs[v]);
      mins[u] = min(mins[u], mins[v]);
      sizes[u] += sizes[v];
    }
  }
  int lca(int u, int v, vector<int>& depths, vector<vector<int>>& pars) {
    if (u == -1) {
      return v;
    }
    if (v == -1) {
      return u;
    }
    if (u == v) {
      return u;
    }
    if (depths[u] > depths[v]) {
      swap(u, v);
    }
    int h = pars[v].size();
    for (int i = h - 1; i >= 0; --i) {
      if (depths[v] - (1 << i) >= depths[u]) {
        v = pars[v][i];
      }
    }
    if (u == v) {
      return u;
    }
    for (int i = h - 1; i >= 0; --i) {
      if (pars[v][i] != pars[u][i]) {
        v = pars[v][i];
        u = pars[u][i];
      }
    }
    return pars[u][0];
  }
  void dfs2(int u, vector<vector<int>>& graph, vector<int>& ord) {
    ord.push_back(u);
    for (auto v : graph[u]) {
      dfs2(v, graph, ord);
      ord.push_back(u);
    }
  }
  void buildCost(vector<int>& L, vector<vector<int>>& pars, vector<int>& depths,
                 vector<vector<int>>& costs) {
    int n = L.size();
    costs.clear();
    costs.resize(n + 1, vector<int>(n + 1, 1234567));
    for (int i = 0; i < n; ++i) {
      costs[0][i + 1] = depths[L[i]];
      for (int j = i + 1; j < n; ++j) {
        int p = lca(L[j], L[i], depths, pars);
        costs[i + 1][j + 1] = depths[L[j]] - depths[p];
      }
    }
  }
  void buildLCA(vector<int>& L, vector<vector<int>>& pars, vector<int>& depths,
                vector<vector<int>>& LCA, vector<vector<int>>& sums) {
    int n = L.size();
    LCA.clear();
    LCA.resize(n, vector<int>(n, -1));
    sums.clear();
    sums.resize(n, vector<int>(n, -1));
    for (int i = 0; i < n; ++i) {
      int p = -1;
      int sum = 0;
      for (int j = i; j < n; ++j) {
        p = lca(p, L[j], depths, pars);
        LCA[i][j] = p;
        if (j == i) {
          sum += depths[L[j]];
        } else {
          int p2 = lca(L[j - 1], L[j], depths, pars);
          sum += depths[L[j]] - depths[p2];
        }
        sums[i][j] = sum;
      }
    }
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  int m;
  cin >> m;
  vector<int> PA(m - 1, 0);
  for (int i = 0; i + 1 < m; ++i) {
    cin >> PA[i];
    --PA[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    --A[i];
  }
  cin >> m;
  vector<int> PB(m - 1, 0);
  for (int i = 0; i + 1 < m; ++i) {
    cin >> PB[i];
    --PB[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> B[i];
    --B[i];
  }
  cout << sol.solve(n, PA, PB, A, B) << "\n";
  return 0;
}
