#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long llinf = (long long)9e18;
const int N = 211;
const long double PI = (long double)acos(-1);
int n, x, ans = inf;
int c[N], k[N];
vector<vector<int> > g;
int cnt(int v) {
  vector<int> k1(n);
  for (int i = 0; i < n; i++) k1[i] = k[i];
  vector<char> us(n, 0);
  int cur = v, rest = n - 1, res = 0;
  while (rest != 0) {
    for (int i = 0; i < (int)g[cur].size(); i++) {
      int to = g[cur][i];
      k1[to]--;
    }
    us[cur] = 1;
    int t = 4, nxt;
    for (int i = 0; i < n; i++) {
      if (us[i] == 1) continue;
      if (k1[i] == 0)
        if ((c[i] >= c[cur] ? c[i] - c[cur] : c[i] + 3 - c[cur]) < t) {
          t = (c[i] >= c[cur] ? c[i] - c[cur] : c[i] + 3 - c[cur]);
          nxt = i;
        }
    }
    cur = nxt;
    res += t;
    rest--;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  g.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 0; i < n; i++) {
    scanf("%d", &k[i]);
    for (int j = 0; j < k[i]; j++) {
      scanf("%d", &x);
      g[x - 1].push_back(i);
    }
  }
  for (int i = 0; i < n; i++)
    if (k[i] == 0) ans = min(ans, cnt(i) + n);
  printf("%d", ans);
  return 0;
}
