#include <bits/stdc++.h>
using namespace std;
int diri[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dirj[] = {0, 1, 0, -1, 1, 1, -1, -1};
int compare(double d1, double d2) {
  if (fabs(d1 - d2) < 1e-9) return 0;
  if (d1 < d2) return -1;
  return 1;
}
struct node {
  long long l, r, m, s;
} arr[250001];
long long num[5001];
int main() {
  int m, n, k;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < (int)m; i++) {
    scanf("%d", &k);
    long long sum = 0;
    long long mx = LONG_LONG_MIN;
    arr[i].s = 0;
    arr[i].r = LONG_LONG_MAX;
    arr[i].m = arr[i].l = LONG_LONG_MIN;
    for (int j = 0; j < (int)k; j++) {
      cin >> num[j];
      arr[i].s += num[j];
      arr[i].l = max(arr[i].l, arr[i].s);
      arr[i].r = min(arr[i].r, arr[i].s);
      arr[i].m = max(arr[i].m, num[j]);
      sum += num[j];
      if (sum < 0)
        sum = 0;
      else
        mx = max(mx, sum);
    }
    arr[i].m = max(arr[i].m, mx);
    arr[i].r = arr[i].s - arr[i].r;
  }
  long long mx = LONG_LONG_MIN;
  long long cur = 0;
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &k);
    k--;
    mx = max(mx, arr[k].m);
    if (cur) mx = max(mx, cur + arr[k].l);
    cur = max(0ll, max(cur + arr[k].s, arr[k].r));
  }
  cout << mx << endl;
  return 0;
}
