#include <bits/stdc++.h>
using namespace std;
static const int maxn = 100010;
int n;
int mc[4][4];
int c[205];
int dep_[205][205];
int depCount_[205];
int dep[205][205];
int depCount[205];
bool taskDone[205];
int result = INT_MAX;
void init() {
  memset(mc, 0, sizeof mc);
  mc[1][2] = 1;
  mc[1][3] = 2;
  mc[2][1] = 2;
  mc[2][3] = 1;
  mc[3][1] = 1;
  mc[3][2] = 2;
}
void delTask(int x) {
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < depCount[i]; ++j) {
      if (dep[i][j] == x) {
        swap(dep[i][j], dep[i][depCount[i] - 1]);
        depCount[i]--;
        break;
      }
    }
  }
}
int& depNum(int x) { return depCount[x]; }
void solve(int cur) {
  for (int i = 0; i < 205; ++i) {
    for (int j = 0; j < 205; ++j) {
      dep[i][j] = dep_[i][j];
    }
  }
  for (int i = 0; i < 205; ++i) {
    depCount[i] = depCount_[i];
  }
  memset(taskDone, false, sizeof taskDone);
  int taskLeft = n;
  int ans = n;
  while (taskLeft > 0) {
    for (int i = 1; i <= n; ++i) {
      if (!taskDone[i]) {
        if (c[i] == cur && depNum(i) == 0) {
          delTask(i);
          taskDone[i] = true;
          taskLeft--;
          i = 0;
        }
      }
    }
    if (taskLeft <= 0) break;
    int next;
    if (cur == 3) {
      next = 1;
    } else {
      next = cur + 1;
    }
    bool canDo = false;
    for (int i = 1; i <= n; ++i) {
      if (!taskDone[i] && c[i] == next && depNum(i) == 0) {
        canDo = true;
        break;
      }
    }
    next = canDo ? next : (cur == 1 ? 3 : cur - 1);
    ans += mc[cur][next];
    cur = next;
  }
  result = min(result, ans);
}
int main() {
  init();
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &c[i]);
    }
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &depCount_[i]);
      for (int j = 0; j < depCount_[i]; ++j) {
        scanf("%d", &dep_[i][j]);
      }
    }
    for (int i = 1; i <= n; ++i) {
      if (depNum(i) == 0) {
        solve(c[i]);
      }
    }
    printf("%d\n", result);
  }
  return 0;
}
