#include <bits/stdc++.h>
using namespace std;
const int N = 605, M = 200010;
const int INF = 2147000000;
const int S = 601, T = 602, DLT = 5000005;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x = x * f;
}
struct edge {
  int v, nx, w;
} e[2 * M];
int n, m, head[N], dis[N], gap[N], ans, id;
void add(int u, int v, int w) {
  e[id].v = v;
  e[id].w = w;
  e[id].nx = head[u];
  head[u] = id;
  id++;
}
void aadd(int u, int v, int w) {
  add(u, v, w);
  add(v, u, 0);
}
int sap(int u, int minf) {
  if (u == T) return minf;
  int res = 0, f, i, j, v, mindis = n;
  for (i = head[u]; i != -1; i = e[i].nx) {
    v = e[i].v;
    if (e[i].w > 0) {
      if (dis[u] == dis[v] + 1) {
        f = sap(v, min(minf - res, e[i].w));
        e[i].w -= f;
        e[i ^ 1].w += f;
        res += f;
        if (dis[S] >= n) return res;
        if (minf == res) break;
      }
      if (dis[v] < mindis) mindis = dis[v];
    }
  }
  if (res == 0) {
    gap[dis[u]]--;
    if (gap[dis[u]] == 0) dis[S] = n;
    dis[u] = mindis + 1;
    gap[dis[u]]++;
  }
  return res;
}
int main() {
  int i, j, k, x, t, p;
  read(n);
  id = 0;
  memset(head, -1, sizeof(head));
  ans = 0;
  for (i = 1; i <= n; i++) {
    read(t);
    while (t--) {
      read(x);
      aadd(i, n + x, INF);
    }
  }
  for (i = 1; i <= n; i++) {
    read(p);
    aadd(S, i, DLT - p);
    ans -= DLT - p;
    aadd(n + i, T, DLT);
  }
  n = 2 * n + 2;
  memset(gap, 0, sizeof(gap));
  memset(dis, 0, sizeof(dis));
  gap[0] = n;
  while (dis[S] < n) ans += sap(S, INF);
  printf("%d\n", ans);
  return 0;
}
