#include <bits/stdc++.h>
using namespace std;
struct ENode {
  int v, c;
  ENode *next, *anti;
};
typedef ENode *elist;
elist de[302];
void AddEdge(int u, int v, int c) {
  elist l0 = new ENode, l1 = new ENode;
  l0->anti = l1;
  l1->anti = l0;
  l0->v = v;
  l1->v = u;
  l0->c = c;
  l1->c = 0;
  l0->next = de[u];
  de[u] = l0;
  l1->next = de[v];
  de[v] = l1;
}
int n;
int match[300];
int weight[300];
bool bigraph[300][300];
bool vis[302];
bool Find(int u) {
  if (vis[u]) return false;
  vis[u] = true;
  for (int v = 0; v < n; v++)
    if (bigraph[u][v]) {
      if (match[v] == -1 || Find(match[v])) {
        match[v] = u;
        return true;
      }
    }
  return false;
}
int S, T;
int DFS(int u, int flow) {
  if (u == T) return flow;
  if (vis[u]) return false;
  vis[u] = true;
  int tmp = 0;
  for (elist l = de[u]; l; l = l->next)
    if (l->c && (tmp = DFS(l->v, min(l->c, flow)))) {
      l->c -= tmp;
      l->anti->c += tmp;
      return tmp;
    }
  return 0;
}
int Aug() {
  memset(vis, 0, sizeof(vis));
  return DFS(S, 1000000000);
}
int main() {
  memset(de, 0, sizeof(de));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; j++) {
      int k;
      scanf("%d", &k);
      k--;
      bigraph[i][k] = true;
    }
  }
  memset(match, -1, sizeof(match));
  for (int i = 0; i < n; i++) {
    memset(vis, 0, sizeof(vis));
    Find(i);
  }
  for (int i = 0; i < n; i++) scanf("%d", weight + i), weight[i] *= -1;
  S = n;
  T = n + 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (bigraph[i][j] && match[j] != i) {
        AddEdge(i, match[j], 1000000000);
      }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (weight[i] > 0) {
      sum += weight[i];
      AddEdge(S, i, weight[i]);
    } else if (weight[i] < 0)
      AddEdge(i, T, -weight[i]);
  }
  int tmp = 0;
  while ((tmp = Aug()) != 0) sum -= tmp;
  printf("%d\n", -sum);
  return 0;
}
