#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 6e2 + 7;
const int MOD = 1e9 + 7;
const double Pi = acos(-1.);
const double EPS = 1e-7;
int et, cur[N], dis[N], que[N], head[N];
struct Edge {
  long long v;
  int s, t, next;
} e[N * N];
void addEdge(int s, int t, long long v) {
  e[et].s = s, e[et].t = t, e[et].v = v, e[et].next = head[s], head[s] = et++;
  e[et].s = t, e[et].t = s, e[et].v = 0, e[et].next = head[t], head[t] = et++;
}
bool bfs(int S, int T, int n) {
  int qh = 0, qt = 0;
  for (int i = 0; i < n; ++i) dis[i] = -1;
  dis[S] = 0, que[qt++] = S;
  while (qh < qt) {
    for (int i = head[que[qh++]]; ~i; i = e[i].next) {
      if (e[i].v && !~dis[e[i].t]) {
        dis[e[i].t] = 1 + dis[e[i].s];
        if (e[i].t == T) return true;
        que[qt++] = e[i].t;
      }
    }
  }
  return false;
}
long long dinic(int S, int T, int n) {
  int u, qt;
  long long maxFlow = 0;
  while (bfs(S, T, n)) {
    for (int i = 0; i < n; ++i) cur[i] = head[i];
    u = S, qt = 0;
    while (~cur[S]) {
      if (u != T && ~cur[u] && e[cur[u]].v && dis[e[cur[u]].t] == 1 + dis[u]) {
        que[qt++] = cur[u];
        u = e[cur[u]].t;
      } else if (u == T) {
        long long tmp = 1LL + (INF << 1);
        for (int i = qt - 1; i >= 0; --i) tmp = min(tmp, e[que[i]].v);
        for (int i = qt - 1; i >= 0; --i) {
          e[que[i]].v -= tmp;
          e[que[i] ^ 1].v += tmp;
          if (!e[que[i]].v) qt = i;
        }
        u = e[que[qt]].s;
        maxFlow += tmp;
      } else {
        while (u != S && !~cur[u]) u = e[que[--qt]].s;
        cur[u] = e[cur[u]].next;
      }
    }
  }
  return maxFlow;
}
int n;
int main() {
  long long sum = 0;
  int S, T;
  scanf("%d", &n);
  S = 0, T = 1 + (n << 1);
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= n; ++i) {
    int m;
    scanf("%d", &m);
    while (m--) {
      int x;
      scanf("%d", &x);
      addEdge(i, x + n, INF << 1);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int pri;
    scanf("%d", &pri);
    sum += pri;
    addEdge(S, i, INF - pri);
  }
  for (int i = 1; i <= n; ++i) {
    addEdge(n + i, T, INF);
  }
  long long ans = sum + dinic(S, T, T + 1) - n * INF;
  printf("%I64d", ans);
  return 0;
}
