#include <bits/stdc++.h>
using namespace std;
const long long N = 3e2 + 5;
const long long BIGinf = 1ll << 60;
const long long inf = 1ll << 30;
inline long long read() {
  register long long s = 0;
  register char c = getchar(), lc = '+';
  while (c < '0' || '9' < c) lc = c, c = getchar();
  while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(register long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x < 10)
    putchar(x + '0');
  else {
    write(x / 10);
    putchar(x % 10 + '0');
  }
}
inline void print(const register long long x, const register char c = '\n') {
  write(x);
  putchar(c);
}
namespace Dinic {
const long long N = 1e3 + 5;
const long long M = N * N + 5;
const long long inf = 1ll << 60;
long long n, S, T, cur[N], head[N], cnt = -1, deep[N];
struct edge {
  long long nxt, to, v;
} e[2 * M];
struct Queue {
  long long now, dis;
} q[N];
void add_edge(long long u, long long v, long long w) {
  e[++cnt].to = v;
  e[cnt].v = w;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
void add(long long u, long long v, long long w) {
  add_edge(u, v, w);
  add_edge(v, u, 0);
}
bool bfs() {
  for (long long i = 1; i <= n; i++) cur[i] = head[i];
  memset(deep, 0, sizeof(deep));
  long long h = 1, t = 1;
  q[1].now = S;
  q[1].dis = 0;
  while (h <= t) {
    long long now = q[h].now, dis = q[h++].dis;
    for (long long i = head[now]; ~i; i = e[i].nxt)
      if (e[i].v) {
        long long to = e[i].to;
        if ((!deep[to]) && to != S) {
          deep[to] = dis + 1;
          q[++t].dis = dis + 1;
          q[t].now = to;
        }
      }
  }
  return deep[T];
}
long long dfs(long long now, long long flow) {
  if (!flow) return 0;
  if (now == T) return flow;
  long long ans = 0, to, v, tmp;
  for (long long i = cur[now]; ~i; i = e[i].nxt) {
    cur[now] = i;
    if (to = e[i].to, v = e[i].v, deep[now] < deep[to])
      if (tmp = dfs(to, min(flow, v))) {
        ans += tmp;
        flow -= tmp;
        e[i].v -= tmp;
        e[i ^ 1].v += tmp;
        if (!flow) return ans;
      }
  }
  cur[now] = -1;
  return ans;
}
long long work() {
  if (S == T) return 0;
  long long ans = 0;
  while (bfs()) ans += dfs(S, BIGinf);
  return ans;
}
void send(long long _n, long long _S, long long _T) {
  memset(head, -1, sizeof(head));
  n = _n;
  S = _S;
  T = _T;
}
}  // namespace Dinic
long long SET[N], NUM[N];
signed main() {
  long long n = read(), S = 1, T = 2, cnt = 2, v, sum = 0;
  for (long long i = 1; i <= n; i++) SET[i] = ++cnt;
  for (long long i = 1; i <= n; i++) NUM[i] = ++cnt;
  Dinic::send(cnt, S, T);
  for (long long i = 1; i <= n; i++) {
    long long m = read();
    for (long long j = 1; j <= m; j++) Dinic::add(SET[i], NUM[read()], inf);
  }
  for (long long i = 1; i <= n; i++)
    Dinic::add(S, SET[i], inf - (v = read())), sum += v;
  for (long long i = 1; i <= n; i++) Dinic::add(NUM[i], T, inf);
  print(sum + (Dinic::work() - inf * n));
  return 0;
}
