#include <bits/stdc++.h>
using namespace std;
int N;
int F[302][302];
int C[302][302];
bool vis[302][2];
int dfs(int x, bool s, int mxf) {
  if (x == N && !s) return mxf;
  if (vis[x][s]) return 0;
  vis[x][s] = true;
  int res = 0;
  for (int i = 0; mxf != 0 && i <= N; i++) {
    int fm = s ? F[i][x] : C[x][i] - F[x][i];
    if (x != N && mxf < fm) fm = mxf;
    if (fm != 0) {
      fm = dfs(i, !s, fm);
      res += fm;
      mxf -= fm;
      if (s) {
        F[i][x] -= fm;
      } else {
        F[x][i] += fm;
      }
    }
  }
  return res;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int M;
    cin >> M;
    for (int j = 0; j < M; j++) {
      int x;
      cin >> x;
      x--;
      C[i][x] = 1000000010;
    }
  }
  int res = -1000000010 * N;
  for (int i = 0; i < N; i++) {
    int w;
    cin >> w;
    res += w;
    F[i][N] = C[i][N] = 1000000010 - w;
    F[N][i] = C[N][i] = 1000000010;
  }
  for (int f = -1; f != 0;) {
    memset(vis, 0, sizeof(vis));
    res += (f = dfs(N, true, -1));
  }
  cout << res << endl;
}
