#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
int S, T;
int v[MAXN + 10];
const int INF = 0x3f3f3f3f;
int n;
struct et {
  int t;
  et* n;
  et() {}
  et(int _t, et* _n) : t(_t), n(_n) {}
} * e[MAXN + 10], store[MAXN * MAXN + 10], *loc = store;
struct et2 {
  int t, u;
  et2 *n, *p;
  et2() {}
  et2(int _t, int _u, et2* _n) : t(_t), u(_u), n(_n) {}
} * e2[MAXN + 10], store2[MAXN * MAXN + 10 + MAXN * 2], *loc2 = store2;
void add(int x, int y, int z) {
  e2[x] = new (loc2++) et2(y, z, e2[x]);
  e2[y] = new (loc2++) et2(x, 0, e2[y]);
  e2[x]->p = e2[y];
  e2[y]->p = e2[x];
}
int d[MAXN + 10];
bool build() {
  static int q[MAXN + 10];
  int head = 0, tail = 0;
  q[0] = S;
  memset(d, 0, sizeof(d));
  d[S] = 1;
  while (head <= tail) {
    int now = q[head++];
    for (et2* i = e2[now]; i; i = i->n) {
      if (!d[i->t] && i->u) {
        d[i->t] = d[now] + 1;
        q[++tail] = i->t;
        if (i->t == T) return true;
      }
    }
  }
  return false;
}
int flow(int x, int left) {
  if (x == T || !left) return left;
  int res = 0;
  for (et2*& i = e2[x]; i; i = i->n)
    if (d[i->t] == d[x] + 1) {
      int got = flow(i->t, min(left, i->u));
      i->u -= got;
      i->p->u += got;
      res += got;
      left -= got;
      if (!left) return res;
    }
  return res;
}
int maxFlow() {
  static et2* eb[MAXN + 10];
  memcpy(eb, e2, sizeof(eb));
  int res = 0;
  while (build()) {
    res += flow(S, INF);
    memcpy(e2, eb, sizeof(eb));
  }
  return res;
}
int goes[MAXN + 10];
bool been[MAXN + 10];
bool find(int x) {
  for (et* i = e[x]; i; i = i->n)
    if (!been[i->t]) {
      been[i->t] = true;
      if (!goes[i->t] || find(goes[i->t])) {
        goes[i->t] = x;
        return true;
      }
    }
  return false;
}
void perfectMatch() {
  for (int i = 1; i <= n; i++) {
    memset(been, false, sizeof(been));
    assert(find(i));
  }
}
int main() {
  scanf("%d", &n);
  S = 1, T = ((n) + 1) + 1;
  for (int i = 1; i <= n; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j <= cnt; j++) {
      int x;
      scanf("%d", &x);
      e[i] = new (loc++) et(x, e[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
  }
  perfectMatch();
  for (int i = 1; i <= n; i++) {
    for (et* j = e[i]; j; j = j->n)
      if (goes[j->t] != i) {
        add(((i) + 1), ((goes[j->t]) + 1), INF);
      }
  }
  int posSum = 0;
  for (int i = 1; i <= n; i++) {
    v[i] = -v[i];
    if (v[i] > 0) {
      add(S, ((i) + 1), v[i]);
      posSum += v[i];
    } else {
      add(((i) + 1), T, -v[i]);
    }
  }
  cout << -(posSum - maxFlow()) << endl;
  return 0;
}
