#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 1e5 + 5;
int m[MAXN];
vector<int> num[MAXN];
const int MX = 666;
int match[MX];
bool vis[MX];
struct Edge {
  int v, nxt;
} E[MAXN];
int Head[MAXN], tot;
void add(int x, int y) {
  E[tot++] = {y, Head[x]};
  Head[x] = tot - 1;
}
bool DFS(int u) {
  for (int i = Head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (!vis[v]) {
      vis[v] = 1;
      if (match[v] == -1 || DFS(match[v])) {
        match[v] = u;
        match[u] = v;
        return 1;
      }
    }
  }
  return 0;
}
int BM(int n) {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int u = 1; u <= n; u++) {
    memset(vis, 0, sizeof(vis));
    if (DFS(u)) res++;
  }
  return res;
}
const int inf = 0x3f3f3f3f;
const int MXE = 4 * MX * MX;
struct MaxFlow {
  struct Edge {
    int v, w, nxt;
  } edge[MXE];
  int tot, num, s, t;
  int head[MX];
  void init() {
    memset(head, -1, sizeof(head));
    tot = 0;
  }
  void add(int u, int v, int w) {
    edge[tot].v = v;
    edge[tot].w = w;
    edge[tot].nxt = head[u];
    head[u] = tot++;
    edge[tot].v = u;
    edge[tot].w = 0;
    edge[tot].nxt = head[v];
    head[v] = tot++;
  }
  int d[MX], vis[MX], gap[MX];
  void bfs() {
    memset(d, 0, sizeof(d));
    memset(gap, 0, sizeof(gap));
    memset(vis, 0, sizeof(vis));
    queue<int> q;
    q.push(t);
    vis[t] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = head[u]; ~i; i = edge[i].nxt) {
        int v = edge[i].v;
        if (!vis[v]) {
          d[v] = d[u] + 1;
          gap[d[v]]++;
          q.push(v);
          vis[v] = 1;
        }
      }
    }
  }
  int last[MX];
  int dfs(int u, int f) {
    if (u == t) return f;
    int sap = 0;
    for (int i = last[u]; ~i; i = edge[i].nxt) {
      int v = edge[i].v;
      if (edge[i].w > 0 && d[u] == d[v] + 1) {
        last[u] = i;
        int tmp = dfs(v, min(f - sap, edge[i].w));
        edge[i].w -= tmp;
        edge[i ^ 1].w += tmp;
        sap += tmp;
        if (sap == f) return sap;
      }
    }
    if (d[s] >= num) return sap;
    if (!(--gap[d[u]])) d[s] = num;
    ++gap[++d[u]];
    last[u] = head[u];
    return sap;
  }
  int solve(int st, int ed, int n) {
    int flow = 0;
    num = n;
    s = st;
    t = ed;
    bfs();
    memcpy(last, head, sizeof(head));
    while (d[s] < num) flow += dfs(s, inf);
    return flow;
  }
} F;
int v[MX];
int main() {
  int n;
  cin >> n;
  memset(Head, -1, sizeof(Head));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &m[i]);
    for (int j = 1; j <= m[i]; j++) {
      int x;
      scanf("%d", &x);
      num[i].push_back(x);
      add(i, x + n);
      add(x + n, i);
    }
  }
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]), v[i] = -v[i];
  BM(n);
  F.init();
  int tot = 0;
  int st = 0, en = n + n + 10;
  for (int i = 1; i <= n; i++) {
    for (int j : num[i]) {
      F.add(match[i] - n, j, INF);
    }
    if (v[i] > 0)
      F.add(st, match[i] - n, v[i]), tot += v[i];
    else
      F.add(match[i] - n, en, -v[i]);
  }
  int ret = F.solve(st, en, en + 5);
  printf("%d\n", -(tot - ret));
  return 0;
}
