#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, true : false;
}
template <class T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, true : false;
}
inline int read(void) {
  int x, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
template <typename T>
struct Graph {
  enum { maxn = 305, maxm = 200000 };
  struct Edge {
    int to, nxt;
    T w, cap, flow;
  } v[maxm];
  int h[maxn], cnt;
  Graph() { memset(h, -1, sizeof(h)); }
  void add1(int x, int y, T w, T cap) {
    v[cnt] = Edge{y, h[x], w, cap, 0};
    h[x] = cnt++;
  }
  void add(int x, int y, T w, T cap) {
    add1(x, y, w, cap);
    add1(y, x, -w, 0);
  }
};
Graph<int> G;
int Ss, Se;
static int f[305];
int dfs(int x, int re) {
  if (x == Se || re <= 0) return re;
  int s1 = 0, t;
  for (int i = G.h[x]; i != -1; i = G.v[i].nxt) {
    int to = G.v[i].to;
    if (f[to] != f[x] + 1) continue;
    t = dfs(to, min(re, G.v[i].cap - G.v[i].flow));
    G.v[i].flow += t;
    G.v[i ^ 1].flow -= t;
    s1 += t;
    re -= t;
    if (re == 0) break;
  }
  return s1;
}
bool bfs(int x) {
  queue<int> Q;
  memset(f, -1, sizeof(f));
  Q.push(x);
  f[x] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = G.h[u]; i != -1; i = G.v[i].nxt) {
      if (G.v[i].flow >= G.v[i].cap) continue;
      int to = G.v[i].to;
      if (f[to] != -1) continue;
      f[to] = f[u] + 1;
      Q.push(to);
    }
  }
  return f[Se] != -1;
}
int dinic() {
  int ans = 0;
  while (bfs(Ss)) ans += dfs(Ss, 1000000000);
  return ans;
}
bool vi[305];
int n, lk[305], v, x, ans, w;
vector<int> V[305];
bool dfs(int x) {
  vi[x] = 1;
  for (int i = 0; i <= V[x].size() - 1; ++i) {
    int to = V[x][i];
    if (!lk[to] || (!vi[lk[to]] && dfs(lk[to]))) {
      lk[to] = x;
      return 1;
    }
  }
  return 0;
}
int main(void) {
  n = read();
  for (int i = 1; i <= n; ++i) {
    v = read();
    while (v--) {
      x = read();
      V[i].push_back(x);
    }
  }
  for (int i = 1; i <= n; ++i) {
    memset(vi, 0, sizeof(vi));
    dfs(i);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= V[i].size() - 1; ++j)
      G.add(i, lk[V[i][j]], 0, 1000000000);
  Ss = n + 1;
  Se = n + 2;
  for (int i = 1; i <= n; ++i) {
    w = -read();
    if (w < 0)
      G.add(i, Se, 0, -w);
    else
      G.add(Ss, i, 0, w), ans += w;
  }
  printf("%d\n", -(ans - dinic()));
  return 0;
}
