#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char ch = getchar(), flag = 0;
  while ((ch > '9' || ch < '0') && ch != '-') ch = getchar();
  if (ch == '-') flag = 1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (flag) x = -x;
}
inline void read(int &x, int &y) { read(x), read(y); }
inline void read(int &x, int &y, int &z) { read(x), read(y), read(z); }
const long long inf = 1e9, INF = 1ll << 50;
struct edge {
  int to, next;
  long long v;
} p[200005];
int head[100005], tot, st[100005];
long long ans = 0;
int n, m, S, T;
bool vis[100005];
inline void add(int x, int y, long long z) {
  p[tot].to = y;
  p[tot].v = z;
  p[tot].next = head[x];
  head[x] = tot++;
  p[tot].to = x;
  p[tot].v = 0;
  p[tot].next = head[y];
  head[y] = tot++;
}
bool bfs(int x) {
  queue<int> q;
  q.push(x);
  memset(st, 0, sizeof(st));
  memset(vis, 0, sizeof(vis));
  vis[x] = true;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i + 1; i = p[i].next) {
      int y = p[i].to;
      long long v = p[i].v;
      if (!v || vis[y]) continue;
      q.push(y);
      st[y] = st[x] + 1;
      vis[y] = true;
    }
  }
  return vis[T];
}
inline long long dfs(int x, long long y) {
  long long r = 0;
  if (x == T) return y;
  for (int i = head[x]; i + 1; i = p[i].next) {
    int q = p[i].to;
    long long v = p[i].v;
    if (!v || st[x] != st[q] - 1) continue;
    int t = min(v, y - r);
    t = dfs(q, t);
    r += t;
    p[i].v -= t;
    p[i ^ 1].v += t;
    if (r == y) return r;
  }
  if (!r) st[x] = -1;
  return r;
}
void dinic() {
  long long t;
  while (bfs(S)) {
    while (t = dfs(S, INF)) ans -= t;
  }
  cout << -ans << endl;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  S = 0;
  T = n * 2 + 1;
  for (int i = 1; i <= n; i++) {
    int num;
    scanf("%d", &num);
    for (int j = 1; j <= num; j++) {
      int y;
      scanf("%d", &y);
      add(i, y + n, INF);
    }
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    add(S, i, inf - x);
    ans += inf - x;
    add(i + n, T, inf);
  }
  dinic();
  return 0;
}
