#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int n, m, a[MAXN], sec[MAXN], tt[MAXN];
long long tl[MAXN], tr[MAXN], mx[MAXN], sum[MAXN];
pair<pair<long long, long long>, pair<long long, long long>> go(int b, int e) {
  if (e - b == 1) {
    b = sec[b];
    return {{tl[b], tr[b]}, {mx[b], sum[b]}};
  }
  int mid = b + e >> 1;
  auto f = go(b, mid), g = go(mid, e);
  auto ff = f;
  ff.second.second += g.second.second;
  ff.second.first =
      max({f.second.first, g.second.first, f.first.second + g.first.first});
  ff.first.first = max(f.first.first, f.second.second + g.first.first);
  ff.first.second = max(g.first.second, g.second.second + f.first.second);
  return ff;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int sz;
    scanf("%d", &sz);
    for (int j = 0; j < sz; j++) scanf("%d", &a[j]);
    long long sm = 0;
    for (int j = 0; j < sz; j++) sm += a[j], tl[i] = max(tl[i], sm);
    sm = 0;
    for (int j = sz - 1; ~j; j--) sm += a[j], tr[i] = max(tr[i], sm);
    sum[i] = sm;
    sm = 0;
    for (int j = 0; j < sz; j++) {
      sm += a[j];
      sm = max(sm, 0ll);
      mx[i] = max(mx[i], sm);
    }
    tt[i] = -2e9;
    for (int j = 0; j < sz; j++) tt[i] = max(tt[i], a[j]);
  }
  int tm = -2e9;
  for (int i = 0; i < m; i++) {
    scanf("%d", &sec[i]), sec[i]--;
    tm = max(tm, tt[sec[i]]);
  }
  if (tm < 0) {
    printf("%d\n", tm);
    return 0;
  }
  auto x = go(0, m);
  printf("%lld\n", x.second.first);
  return 0;
}
