#include <bits/stdc++.h>
using namespace std;
const int N = 910;
const int M = 1e5 + 10;
const long long inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct edge {
  int to, nxt;
  long long fl;
} e[M << 1];
int head[N], tot = 1;
int cur[N];
int dep[N], vis[N];
int le[N], ri[N], eid = 0, S, T;
void addedge(int u, int v, long long w) {
  e[++tot] = edge{v, head[u], w};
  return head[u] = tot, void();
}
void adde(int u, int v, long long w) {
  addedge(u, v, w);
  addedge(v, u, 0);
  return;
}
int bfs(int s, int t, int n) {
  for (int i = 1; i <= n; i++) cur[i] = head[i], dep[i] = 0, vis[i] = 0;
  queue<int> q;
  q.push(s);
  vis[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = cur[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (!vis[v] && e[i].fl) {
        dep[v] = dep[u] + 1;
        vis[v] = 1;
        q.push(v);
      }
    }
  }
  return vis[t];
}
long long dfs(int u, int t, long long in) {
  if (u == t || !in) return in;
  long long flow = 0, f;
  for (int i = cur[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (dep[v] == dep[u] + 1 && (f = dfs(v, t, min(in, e[i].fl))) > 0) {
      e[i].fl -= f, e[i ^ 1].fl += f, flow += f;
      in -= f;
    }
    if (!in) break;
  }
  if (flow == 0) dep[u] = -1;
  return flow;
}
long long dinic(int s, int t, int n) {
  long long flow = 0;
  while (bfs(s, t, n)) flow += dfs(s, t, INF);
  return flow;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) le[i] = ++eid, ri[i] = ++eid;
  S = ++eid, T = ++eid;
  for (int i = 1; i <= n; i++) {
    int m;
    scanf("%d", &m);
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      adde(le[i], ri[x], INF);
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    adde(S, le[i], inf - x);
    sum += inf - x;
  }
  for (int i = 1; i <= n; i++) adde(ri[i], T, inf);
  sum -= dinic(S, T, eid);
  printf("%lld\n", -sum);
  return 0;
}
