#include <bits/stdc++.h>
inline int rd() {
  int x = 0, p = 1;
  char a = getchar();
  while ((a < 48 || a > 57) && a != '-') a = getchar();
  if (a == '-') p = -p, a = getchar();
  while (a > 47 && a < 58) x = (x << 1) + (x << 3) + (a & 15), a = getchar();
  return x * p;
}
template <typename T>
inline T min(T x, T y) {
  return x < y ? x : y;
}
const int N = 200002;
struct Edge {
  int to, next;
  long long flow;
} edge[N << 1];
int head[N], cnt = -1;
int n, s, t;
long long ans;
inline void add(int f, int t, long long w) {
  edge[++cnt].next = head[f];
  edge[cnt].to = t;
  edge[cnt].flow = w;
  head[f] = cnt;
}
inline void ins(int u, int v, long long f) { add(u, v, f), add(v, u, 0); }
int h[N], gap[N];
long long e[N];
int vis[N];
struct cmp {
  bool operator()(const int &x, const int &y) const { return h[x] < h[y]; }
};
std::priority_queue<int, std::vector<int>, cmp> q;
inline void bfs() {
  std::queue<int> q;
  for (int i = 1; i <= t; i++) h[i] = (2100000000);
  h[t] = 0, q.push(t);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if (edge[i ^ 1].flow && h[v] > h[u] + 1) h[v] = h[u] + 1, q.push(v);
    }
  }
}
inline void push(int u) {
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (edge[i].flow && h[u] == h[v] + 1) {
      long long f = min(e[u], edge[i].flow);
      edge[i].flow -= f, edge[i ^ 1].flow += f;
      e[u] -= f, e[v] += f;
      if (v != s && v != t && !vis[v]) q.push(v), vis[v] = 1;
    }
    if (!e[u]) break;
  }
}
inline void relable(int u) {
  h[u] = (2100000000);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (edge[i].flow && h[u] > h[v] + 1) h[u] = h[v] + 1;
  }
}
inline long long HLPP() {
  bfs();
  if (h[s] == (2100000000)) return 0;
  h[s] = t;
  for (int i = 1; i <= t; i++)
    if (h[i] != (2100000000)) gap[h[i]]++;
  for (int i = head[s]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    long long f = 0;
    if ((f = edge[i].flow)) {
      edge[i].flow -= f, edge[i ^ 1].flow += f;
      e[s] -= f, e[v] += f;
      if (v != s && v != t && !vis[v]) q.push(v), vis[v] = 1;
    }
  }
  while (!q.empty()) {
    int u = q.top();
    q.pop();
    vis[u] = 0, push(u);
    if (e[u]) {
      gap[h[u]]--;
      if (!gap[h[u]])
        for (int v = 1; v <= t; v++)
          if (v != s && v != t && h[v] < t + 1 && h[u] < h[v]) h[v] = t + 1;
      relable(u), gap[h[u]]++;
      q.push(u), vis[u] = 1;
    }
  }
  return e[t];
}
int main() {
  memset(head, -1, sizeof head);
  n = rd();
  s = n + n + 1, t = s + 1;
  for (int i = 1; i <= n; i++) {
    int x = rd(), v;
    while (x--) {
      v = rd();
      ins(i, v + n, (210000000000ll));
    }
    ins(i + n, t, (500000000));
  }
  for (int i = 1; i <= n; i++) {
    int x = rd();
    ins(s, i, -x + (500000000));
    ans += (-x + (500000000));
  }
  printf("%lld\n", min(-(ans - HLPP()), 0ll));
  return 0;
}
