#include <bits/stdc++.h>
using namespace std;
vector<int> tmap[210], comp[4];
int din[210];
inline int MIN(int x, int y) { return x < y ? x : y; }
void initin(int n) {
  memset(din, 0, sizeof(din));
  for (int i = 1; i <= n; i++) {
    for (size_t j = 0; j < tmap[i].size(); j++) {
      din[tmap[i][j]]++;
    }
  }
}
int cha[4][4];
void prework() {
  cha[1][3] = cha[2][3] = cha[3][1] = 1;
  cha[1][3] = cha[3][2] = cha[2][1] = 2;
}
int dfs(int st, int n, int *in) {
  int ans = 0;
  bool c;
  do {
    c = false;
    for (size_t i = 0; i < comp[st].size(); i++) {
      int x = comp[st][i];
      if (in[x] == 0) {
        in[x] = -1;
        ans++;
        c = true;
        for (size_t j = 0; j < tmap[x].size(); j++) {
          in[tmap[x][j]]--;
        }
      }
    }
  } while (c);
  bool re = true;
  for (int i = 1; i <= n; i++) {
    if (in[i] >= 0) re = false;
  }
  if (re) {
    return ans;
  }
  int to = st + 1;
  if (to > 3) to = 1;
  return ans + 1 + dfs(to, n, in);
}
int main() {
  setvbuf(stdout, NULL, _IONBF, 0);
  int n;
  while (scanf(" %d", &n) == 1) {
    for (int i = 1; i <= n; i++) {
      int x;
      scanf(" %d", &x);
      comp[x].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      int k;
      scanf(" %d", &k);
      while (k--) {
        int x;
        scanf(" %d", &x);
        tmap[x].push_back(i);
      }
    }
    int ans = 1000010000;
    for (int i = 1; i <= 3; i++) {
      initin(n);
      ans = MIN(dfs(i, n, din), ans);
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) {
      tmap[i].clear();
    }
    for (int i = 1; i <= 3; i++) {
      comp[i].clear();
    }
  }
  return 0;
}
