#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const long long N = 605, M = 200005, oo = 1e9, inf = 1e18;
long long di[M], nxt[M], ed[M];
long long son[N], nedge, cur[N], deep[N];
inline void aedge(long long a, long long b, long long c) {
  nxt[++nedge] = son[a];
  son[a] = nedge;
  ed[nedge] = b;
  di[nedge] = c;
}
inline void insert(long long a, long long b, long long c) {
  aedge(a, b, c);
  aedge(b, a, 0);
}
inline bool bfs(long long s, long long t) {
  for (long long i = 0; i < N; i++) deep[i] = inf;
  for (long long i = 0; i < N; i++) cur[i] = son[i];
  deep[s] = 0;
  queue<long long> q;
  q.push(s);
  while (!q.empty()) {
    long long now = q.front();
    q.pop();
    for (long long tmp = son[now]; tmp; tmp = nxt[tmp])
      if (deep[ed[tmp]] >= inf && di[tmp]) {
        deep[ed[tmp]] = deep[now] + 1, q.push(ed[tmp]);
      }
  }
  return deep[t] < inf;
}
long long dfs(long long now, long long t, long long limit) {
  if (!limit || now == t) return limit;
  long long flow = 0, f;
  for (long long tmp = cur[now]; tmp; tmp = nxt[tmp]) {
    cur[now] = tmp;
    if (deep[ed[tmp]] == deep[now] + 1 &&
        (f = dfs(ed[tmp], t, min(limit, di[tmp])))) {
      flow += f;
      limit -= f;
      di[tmp] -= f;
      di[((tmp - 1) ^ 1) + 1] += f;
      if (!limit) break;
    }
  }
  return flow;
}
inline long long dinic(long long s, long long t) {
  long long ans = 0;
  while (bfs(s, t)) {
    ans += dfs(s, t, inf);
  }
  return ans;
}
signed main() {
  long long n = read(), s = 2 * n + 1, t = 2 * n + 2;
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    long long m = read();
    while (m--) insert(i, n + read(), inf);
  }
  long long sum = 0;
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    long long jj = -read();
    insert(s, i, oo + jj);
    insert(n + i, t, oo);
    sum += oo + jj;
  }
  writeln(-(sum - dinic(s, t)));
}
