#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int adj, next;
} e[40000];
int n, tot, in[210], loc[210], head[210], tmp[210], vis[210];
int dis[4][4] = {0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 1, 0, 1, 2, 0};
int main() {
  int tot = 0;
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", loc + i);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    in[i] = k;
    for (int j = 1; j <= k; j++) {
      int t;
      scanf("%d", &t);
      e[tot].adj = i;
      e[tot].next = head[t];
      head[t] = tot++;
    }
  }
  int min_cost = 0x7fffffff;
  for (int start = 1; start <= 3; start++) {
    memcpy(tmp, in, sizeof(in));
    memset(vis, 0, sizeof(vis));
    int cur_loc = start, cost = 0;
    while (1) {
      int min_dis = 100, next;
      for (int i = 1; i <= n; i++)
        if (!vis[i] && tmp[i] == 0 && dis[cur_loc][loc[i]] < min_dis) {
          min_dis = dis[cur_loc][loc[i]];
          next = i;
        }
      if (min_dis == 100) break;
      vis[next] = 1;
      cost += min_dis + 1;
      for (int v = head[next]; v != -1; v = e[v].next) tmp[e[v].adj]--;
      cur_loc = loc[next];
    }
    if (cost < min_cost) min_cost = cost;
  }
  printf("%d\n", min_cost);
  return 0;
}
