#include <bits/stdc++.h>
using namespace std;
long long m, n, x, y, z, p, q;
long long ara[300000];
long long tmpara[200000];
struct _info {
  long long ans, sum, prefsum, sufsum;
} segtree[1000000], forchotoara[100];
void merge(long long node) {
  long long lft = 2 * node, rgh = 2 * node + 1;
  segtree[node].sum = segtree[lft].sum + segtree[rgh].sum;
  segtree[node].prefsum =
      max(segtree[lft].prefsum, segtree[lft].sum + segtree[rgh].prefsum);
  segtree[node].sufsum =
      max(segtree[rgh].sufsum, segtree[rgh].sum + segtree[lft].sufsum);
  segtree[node].ans = max(segtree[lft].ans, segtree[rgh].ans);
  segtree[node].ans =
      max(segtree[node].ans, (segtree[lft].sufsum + segtree[rgh].prefsum));
}
void update(long long node, long long beg, long long end, long long i,
            long long ans, long long sum, long long prefsum, long long sufsum) {
  if (beg > i || end < i) return;
  if (beg == end) {
    segtree[node].ans = ans;
    segtree[node].sum = sum;
    segtree[node].prefsum = prefsum;
    segtree[node].sufsum = sufsum;
    return;
  }
  long long mid = (beg + end) / 2;
  update(2 * node, beg, mid, i, ans, sum, prefsum, sufsum);
  update((2 * node) + 1, mid + 1, end, i, ans, sum, prefsum, sufsum);
  merge(node);
}
int main() {
  for (long long i = 0; i < 1000000; i++)
    segtree[i].ans = segtree[i].prefsum = segtree[i].sufsum = segtree[i].sum =
        -1000000000000000;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &x);
    bool flg = false;
    long long mx = -10000000000000;
    long long prf = -10000000000000;
    long long suf = -10000000000000;
    long long tmp = 0;
    for (long long j = 1; j <= x; j++) {
      scanf("%lld", &tmpara[j]);
      tmp += tmpara[j];
      prf = max(prf, tmp);
      if (tmpara[j] > 0) flg = true;
      mx = max(mx, tmpara[j]);
    }
    tmp = 0;
    for (long long j = x; j >= 1; j--) tmp += tmpara[j], suf = max(suf, tmp);
    forchotoara[i].sum = tmp;
    forchotoara[i].prefsum = prf;
    forchotoara[i].sufsum = suf;
    if (!flg) {
      forchotoara[i].ans = mx;
      continue;
    }
    mx = 0;
    tmp = 0;
    for (long long j = 1; j <= x; j++) {
      tmp += tmpara[j];
      mx = max(mx, tmp);
      if (tmp < 0) tmp = 0;
    }
    forchotoara[i].ans = mx;
  }
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", &x);
    update(1, 1, m, i, forchotoara[x].ans, forchotoara[x].sum,
           forchotoara[x].prefsum, forchotoara[x].sufsum);
  }
  cout << segtree[1].ans << endl;
  return 0;
}
