#include <bits/stdc++.h>
using namespace std;
const int N = 310, inf = INT_MAX / 3;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') ch = getchar(), f = -1;
  while (ch >= '0' & ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
struct node {
  int to, nxt, flow;
} edge[N * N * 2 + N * 4];
int head[N * 2], gcnt, deep[N * 2], cur[N * 2], s, t, n, ans, val[N], table[N];
vector<int> v[N];
queue<int> q;
void add(int x, int y, int z) {
  edge[++gcnt] = (node){y, head[x], z};
  head[x] = gcnt;
}
bool bfs() {
  int i, j, x, y;
  memset(deep, 0, sizeof(deep));
  memcpy(cur, head, sizeof(head));
  q.push(s);
  deep[s] = 1;
  while (!q.empty()) {
    x = q.front(), q.pop();
    for (i = head[x]; i != -1; i = edge[i].nxt) {
      y = edge[i].to;
      if (deep[y] || !edge[i].flow) continue;
      deep[y] = deep[x] + 1, q.push(y);
    }
  }
  return deep[t];
}
int dfs(int x, int flow) {
  int nflow, y, used = 0, i;
  if (flow == 0 || x == t) return flow;
  for (i = cur[x]; i != -1; i = edge[i].nxt, cur[x] = i) {
    y = edge[i].to;
    if (!edge[i].flow || deep[y] != deep[x] + 1) continue;
    if (nflow = dfs(y, min(edge[i].flow, flow - used))) {
      used += nflow, edge[i].flow -= nflow, edge[i ^ 1].flow += nflow;
      if (used == flow) break;
    }
  }
  if (used == 0) deep[x] = -1;
  return used;
}
void Dinic() {
  while (bfs()) ans += dfs(s, inf);
}
int main() {
  memset(head, -1, sizeof(head)), gcnt = -1;
  int i, j, x, y, z, sum = 0;
  n = read();
  s = n * 2 + 1, t = s + 1;
  for (i = 1; i <= n; i++) {
    y = read();
    v[i].resize(y);
    for (j = 0; j < v[i].size(); j++)
      v[i][j] = read(), add(i, v[i][j] + n, 1), add(v[i][j] + n, i, 0);
  }
  for (i = 1; i <= n; i++) val[i] = -read();
  for (i = 1; i <= n; i++)
    add(s, i, 1), add(i, s, 0), add(i + n, t, 1), add(t, i + n, 0);
  Dinic();
  for (i = 1; i <= n; i++) {
    for (j = head[i]; j != -1; j = edge[j].nxt)
      if (edge[j].flow == 0 && edge[j].to != s) {
        table[edge[j].to - n] = i;
        break;
      }
  }
  memset(head, -1, sizeof(head)), gcnt = -1;
  s = n + 1, t = s + 1, ans = 0;
  for (i = 1; i <= n; i++) {
    if (val[i] > 0)
      add(s, i, val[i]), add(i, s, 0), sum += val[i];
    else
      add(i, t, -val[i]), add(t, i, 0);
    for (j = 0; j < v[i].size(); j++)
      add(i, table[v[i][j]], inf), add(table[v[i][j]], i, 0);
  }
  Dinic();
  cout << min(0, -sum + ans);
  return ~~(0 - 0);
}
