#include <bits/stdc++.h>
using namespace std;
int n, c[300], edge[205][205], pt[205];
queue<int> que[5];
int main() {
  int i, j, a, b;
  memset(pt, 0, sizeof(pt));
  memset(edge, 0, sizeof(edge));
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (i = 1; i <= 3; i++)
    while (!que[i].empty()) que[i].pop();
  for (i = 1; i <= n; i++) {
    scanf("%d", &edge[i][0]);
    if (edge[i][0] == 0) {
      que[c[i]].push(i);
    }
    for (j = 1; j <= edge[i][0]; j++) {
      scanf("%d", &a);
      edge[a][++pt[a]] = i;
    }
  }
  queue<int> bak_que[5];
  for (i = 1; i <= 3; i++) bak_que[i] = que[i];
  int bac_edge0[205];
  for (i = 1; i <= n; i++) bac_edge0[i] = edge[i][0];
  int result = 1 << 30;
  int st;
  for (st = 1; st <= 3; st++) {
    for (i = 1; i <= 3; i++) que[i] = bak_que[i];
    for (i = 1; i <= n; i++) edge[i][0] = bac_edge0[i];
    int sum = 0;
    int cnt = n;
    int now = st;
    while (cnt != 0) {
      while (!que[now].empty()) {
        int front = que[now].front();
        que[now].pop();
        sum++;
        cnt--;
        for (j = 1; j <= pt[front]; j++) {
          a = edge[front][j];
          edge[a][0]--;
          if (edge[a][0] == 0) {
            que[c[a]].push(a);
          }
        }
      }
      now++;
      if (cnt != 0) sum++;
      if (now > 3) now = 1;
    }
    if (sum < result) result = sum;
  }
  printf("%d\n", result);
}
