#include <bits/stdc++.h>
using namespace std;
int n, m, b, l[50];
long long a[50][5000], sum[50], maxbeg[50], maxend[50], maxx[50], s,
    mm = -1000000000;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
    maxbeg[i] = -1000000000;
    maxend[i] = -1000000000;
    for (int j = 0; j < l[i]; j++) {
      scanf("%I64d", &a[i][j]);
      sum[i] = sum[i] + a[i][j];
      maxbeg[i] = max(maxbeg[i], sum[i]);
    }
    s = 0;
    for (int j = l[i] - 1; j >= 0; j--) {
      s += a[i][j];
      maxend[i] = max(maxend[i], s);
    }
    maxx[i] = a[i][0];
    for (int j = 1; j < l[i]; j++)
      if (a[i][j - 1] > 0) {
        a[i][j] += a[i][j - 1];
        maxx[i] = max(maxx[i], a[i][j]);
      } else {
        maxx[i] = max(maxx[i], a[i][j]);
      }
  }
  s = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &b);
    --b;
    s = max(s, 0LL);
    mm = max(mm, maxx[b]);
    mm = max(mm, s + maxbeg[b]);
    s += sum[b];
    s = max(s, maxend[b]);
    mm = max(mm, s);
  }
  cout << mm;
  return 0;
}
