#include <bits/stdc++.h>
using namespace std;
const int _ = 600 + 7;
const int __ = 1e5 + 7;
const int S = 601, T = 602;
const int inf = 0x3f3f3f3f;
int n;
int lst[_], nxt[__], to[__], cap[__], tot = 1;
long long ans;
int gi() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c) and c != '-') c = getchar();
  if (c == '-') f = 1, c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return f ? -x : x;
}
void Add(int x, int y, int c) {
  nxt[++tot] = lst[x];
  to[tot] = y;
  cap[tot] = c;
  lst[x] = tot;
  nxt[++tot] = lst[y];
  to[tot] = x;
  cap[tot] = 0;
  lst[y] = tot;
}
void Init() {
  n = gi();
  for (int i = 1; i <= n; ++i) {
    int m = gi();
    for (int j = 1; j <= m; ++j) Add(i, gi() + n, inf);
  }
  for (int i = 1; i <= n; ++i) {
    int v = gi();
    ans -= v;
    Add(S, i, inf - v), Add(i + n, T, inf);
  }
}
int d[_], cur[_];
queue<int> q;
bool Bfs() {
  memset(d, -1, sizeof d);
  while (!q.empty()) q.pop();
  d[S] = 0, q.push(S);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = lst[u]; i; i = nxt[i])
      if (cap[i] and d[to[i]] == -1) {
        d[to[i]] = d[u] + 1, q.push(to[i]);
        if (to[i] == T) return 1;
      }
  }
  return 0;
}
int Dfs(int u, int flow) {
  if (u == T) return flow;
  int res = flow;
  for (int &i = cur[u]; i; i = nxt[i])
    if (cap[i] and d[to[i]] == d[u] + 1) {
      int tmp = Dfs(to[i], min(res, cap[i]));
      cap[i] -= tmp, cap[i ^ 1] += tmp;
      res -= tmp;
      if (!res) return flow;
    }
  return flow - res;
}
void Run() {
  long long maxFlow = -1ll * n * inf;
  int flow;
  while (Bfs()) {
    memcpy(cur, lst, sizeof cur);
    do {
      flow = Dfs(S, inf);
      maxFlow += flow;
    } while (flow);
  }
  cout << min(0ll, -(ans - maxFlow)) << endl;
}
int main() {
  Init();
  Run();
  return 0;
}
