#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
int n, m;
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
const int Maxn = 605, Maxm = Maxn * Maxn;
const long long Inf = 1ll << 60, zero = 5000000;
long long ans;
struct edge {
  int to, next;
  long long cap;
} e[Maxm];
int h[Maxn], tot, s, t;
inline void add(int u, int v, long long w) {
  e[++tot] = (edge){v, h[u], w};
  h[u] = tot;
  e[++tot] = (edge){u, h[v], 0};
  h[v] = tot;
}
bool vis[Maxn];
int l, r, que[Maxn], d[Maxn], cur[Maxn];
inline bool bfs() {
  l = 0;
  r = 1;
  que[r] = s;
  vis[s] = true;
  do {
    int u = que[++l];
    for (int i = h[u], v; ~i; i = e[i].next)
      if (e[i].cap && !vis[v = e[i].to]) {
        vis[v] = true;
        d[v] = d[u] + 1;
        que[++r] = v;
      }
  } while (l < r);
  return vis[t];
}
long long dfs(int u, long long a) {
  if (u == t || a == 0) return a;
  long long f, flow = 0;
  for (int &i = cur[u], v; ~i; i = e[i].next) {
    if (d[u] + 1 == d[v = e[i].to] && (f = dfs(v, min(a, e[i].cap)))) {
      e[i].cap -= f;
      e[i ^ 1].cap += f;
      flow += f;
      a -= f;
      if (a == 0) break;
    }
  }
  return flow;
}
int main() {
  memset(h, -1, sizeof(h));
  tot = -1;
  n = gi();
  s = n * 2 + 1;
  t = s + 1;
  for (int t, i = 1; i <= n; ++i) {
    t = gi();
    while (t--) add(i, gi() + n, Inf);
  }
  for (int i = 1; i <= n; ++i) add(i + n, t, zero);
  for (int p, i = 1; i <= n; ++i) {
    scanf("%d", &p);
    add(s, i, zero - p);
    ans -= zero - p;
  }
  while (bfs()) {
    memset(vis, 0, sizeof(bool) * (t + 1));
    memcpy(cur, h, sizeof(int) * (t + 1));
    ans += dfs(s, Inf);
  }
  printf("%lld\n", ans);
  return 0;
}
