#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 10;
const int maxm = maxn * maxn;
const int INF = 0x3f3f3f3f;
int connect[maxn][maxn], edgecnt[maxn];
int price[maxn], vis[maxn * 2], match[maxn * 2];
int n;
bool extend(int u) {
  vis[u] = true;
  for (int i = 1; i <= edgecnt[u]; i++) {
    int v = connect[u][i] + n;
    if (vis[v] || v == match[u]) continue;
    vis[v] = true;
    if (match[v] == 0 || extend(match[v])) {
      match[u] = v;
      match[v] = u;
      return true;
    }
  }
  return false;
}
void Match() {
  memset(match, 0, sizeof(match));
  for (int i = 1; i <= n; i++) {
    if (match[i]) continue;
    memset(vis, 0, sizeof(vis));
    extend(i);
  }
  for (int i = 1; i <= 2 * n; i++) {
  }
}
int S, T;
struct Edge {
  Edge *n, *o;
  int v, c, w;
  void init(int _v, int _c, int _w) {
    v = _v;
    c = _c;
    w = _w;
  }
};
Edge *E[maxn * 2], Er[maxn * maxn * 2];
int Es = 0;
void addedge(int u, int v, int c, int w) {
  static Edge *P1, *P2;
  P1 = &Er[++Es];
  P2 = &Er[++Es];
  P1->init(v, c, w);
  P1->n = E[u];
  P1->o = P2;
  E[u] = P1;
  P2->init(u, 0, -w);
  P2->n = E[v];
  P2->o = P1;
  E[v] = P2;
}
int H[maxn * 2];
bool V[maxn * 2];
bool BFS() {
  static int Q[maxn * 20], bot, u, v;
  memset(H, INF, sizeof(H));
  memset(V, true, sizeof(V));
  H[Q[bot = 1] = S] = 0;
  V[S] = false;
  for (int top = 1; top <= bot; top++) {
    u = Q[top];
    for (Edge *P = E[u]; P; P = P->n)
      if (P->c && H[P->v] > H[u] + 1) {
        H[P->v] = H[u] + 1;
        if (V[P->v]) {
          Q[++bot] = P->v;
          V[P->v] = false;
        }
      }
    V[u] = true;
  }
  return H[T] < INF;
}
int extend(int u, int lefts) {
  if (u == T) {
    return lefts;
  }
  V[u] = false;
  int ret = 0, t;
  for (Edge *P = E[u]; P && ret < lefts; P = P->n) {
    if (P->c && V[P->v] && H[u] + 1 == H[P->v]) {
      t = extend(P->v, min(lefts - ret, P->c));
      ret += t;
      P->c -= t;
      P->o->c += t;
    }
  }
  V[u] = true;
  if (ret < lefts) H[u] = INF;
  return ret;
}
int maxflow() {
  int ret = 0, cnt = 0;
  while (BFS()) {
    ret += extend(S, INF);
  }
  return ret;
}
void build() {
  memset(E, 0, sizeof(E));
  for (int i = 1; i <= n; i++) {
    if (price[i] >= 0) {
      addedge(S, i, price[i], 1);
    } else {
      addedge(i, T, -price[i], 1);
    }
    for (int j = 1; j <= edgecnt[i]; j++) {
      int t = match[connect[i][j] + n];
      addedge(i, t, INF, 1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &edgecnt[i]);
    for (int j = 1; j <= edgecnt[i]; j++) {
      scanf("%d", &connect[i][j]);
    }
  }
  S = 0;
  T = 2 * n + 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", price + i);
    price[i] *= -1;
    if (price[i] >= 0) ans += price[i];
  }
  Match();
  build();
  ans = maxflow() - ans;
  cout << ans << endl;
  return 0;
}
