#include <bits/stdc++.h>
using namespace std;
const int N = 305, INF = 1e9;
const long long INFll = INF * 1000ll;
int n, m, x, y, s, t, dep[N << 1];
int head[N << 1], ecnt = 1, fir[N << 1];
long long ans;
queue<int> q;
struct edge {
  int to;
  long long w;
  int nxt;
} e[N * N << 2];
inline void add(int x, int y, long long z) {
  e[++ecnt] = {y, z, head[x]};
  head[x] = ecnt;
}
inline bool bfs(int s, int t) {
  memset(dep, 0, sizeof(dep));
  memcpy(fir, head, sizeof(fir));
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (register int i = head[x]; i; i = e[i].nxt)
      if (e[i].w && !dep[y = e[i].to]) dep[y] = dep[x] + 1, q.push(y);
  }
  return dep[t];
}
long long dfs(int x, int t, long long f) {
  if (x == t) return f;
  long long ff, res = 0;
  for (int i = fir[x]; i; i = fir[x] = e[i].nxt)
    if (e[i].w && dep[e[i].to] == dep[x] + 1) {
      ff = dfs(e[i].to, t, min(f, e[i].w));
      if (ff) {
        f -= ff;
        res += ff;
        e[i].w -= ff;
        e[i ^ 1].w += ff;
        if (!f) break;
      }
    }
  return res;
}
int main() {
  scanf("%d", &n);
  s = n + n + 1;
  t = n + n + 2;
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &m);
    for (register int j = 1; j <= m; j++)
      scanf("%d", &x), add(i, n + x, INFll), add(n + x, i, 0);
  }
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &x);
    x = INF - x;
    ans += x;
    add(s, i, x);
    add(i, s, 0);
    add(n + i, t, INF);
    add(t, n + i, 0);
  }
  while (bfs(s, t)) ans -= dfs(s, t, INFll);
  printf("%lld", min(-ans, 0ll));
}
