#include <bits/stdc++.h>
using namespace std;
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return f * s;
}
struct edge {
  int to, lt, f;
} e[310 * 310 * 4];
queue<int> que;
int dep[310], cnt = 1, in[310], s, t;
void add(int x, int y, int f) {
  e[++cnt].to = y;
  e[cnt].lt = in[x];
  e[cnt].f = f;
  in[x] = cnt;
  e[++cnt].to = x;
  e[cnt].lt = in[y];
  e[cnt].f = 0;
  in[y] = cnt;
}
bool bfs() {
  while (!que.empty()) que.pop();
  memset(dep, 0, sizeof(dep));
  que.push(s);
  dep[s] = 1;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (int i = in[x]; i; i = e[i].lt)
      if (e[i].f && !dep[e[i].to]) {
        que.push(e[i].to), dep[e[i].to] = dep[x] + 1;
        if (e[i].to == t) return 1;
      }
  }
  return 0;
}
int dfs(int x, int flow) {
  if (x == t) return flow;
  int cur = flow;
  for (int i = in[x]; i; i = e[i].lt)
    if (e[i].f && dep[e[i].to] == dep[x] + 1) {
      int tmp = dfs(e[i].to, min(e[i].f, cur));
      e[i].f -= tmp;
      e[i ^ 1].f += tmp;
      cur -= tmp;
      if (!cur) return flow;
    }
  dep[x] = -1;
  return flow - cur;
}
int dinic() {
  int ans = 0;
  while (bfs()) ans += dfs(s, 2002122500);
  return ans;
}
int k[310], edg[310][310], p[310], a[310], n;
bool vis[310];
bool match(int x) {
  for (int i = 1; i <= k[x]; i++)
    if (!vis[edg[x][i]]) {
      vis[edg[x][i]] = 1;
      if (!p[edg[x][i]] || match(p[edg[x][i]])) return p[edg[x][i]] = x, true;
    }
  return false;
}
void Match() {
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    match(i);
  }
}
void build() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k[i]; j++)
      if (p[edg[i][j]] != i) add(i, p[edg[i][j]], 2002122500);
}
int main() {
  s = 310 - 3;
  t = s + 1;
  n = read();
  for (int i = 1; i <= n; i++) {
    k[i] = read();
    for (int j = 1; j <= k[i]; j++) edg[i][j] = read();
  }
  int ful = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = -read();
    if (a[i] >= 0)
      add(s, i, a[i]), ful += a[i];
    else
      add(i, t, -a[i]);
  }
  Match();
  build();
  printf("%d\n", dinic() - ful);
  return 0;
}
