#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
const int M = 1000001;
long long s[N], mxHead[N], mxTail[N], sum[N], b[N], mxSeg[N];
long long mx[M], sm[M], mxH[M], mxT[M];
int idx[M];
int n, m, k;
long long max3(long long a, long long b, long long c) {
  return max(max(a, b), c);
}
void build(int x, int l, int h) {
  if (l == h) {
    int i = l;
    mxH[x] = mxHead[idx[i]];
    mxT[x] = mxTail[idx[i]];
    sm[x] = sum[idx[i]];
    mx[x] = mxSeg[idx[i]];
    return;
  }
  int m = (l + h) / 2;
  build(x * 2, l, m);
  build(x * 2 + 1, m + 1, h);
  mxH[x] = max(mxH[x * 2], sm[x * 2] + mxH[x * 2 + 1]);
  mxT[x] = max(mxT[x * 2 + 1], sm[x * 2 + 1] + mxT[x * 2]);
  sm[x] = sm[x * 2] + sm[x * 2 + 1];
  mx[x] = max3(mx[x * 2], mx[x * 2 + 1], mxT[x * 2] + mxH[x * 2 + 1]);
}
int main() {
  cin >> n >> m;
  long long r = -1000000;
  for (int i = 0; i < n; i++) {
    cin >> k;
    long long curr = 0;
    mxSeg[i] = -1000000000;
    for (int j = 0; j < k; j++) {
      cin >> b[j];
      curr += b[j];
      mxSeg[i] = max(mxSeg[i], curr);
      curr = max(curr, 0ll);
    }
    s[0] = b[0];
    mxHead[i] = s[0];
    for (int j = 1; j < k; j++) {
      s[j] = s[j - 1] + b[j];
      mxHead[i] = max(mxHead[i], s[j]);
    }
    s[k - 1] = b[k - 1];
    mxTail[i] = s[k - 1];
    for (int j = k - 2; j >= 0; j--) {
      s[j] = s[j + 1] + b[j];
      mxTail[i] = max(mxTail[i], s[j]);
    }
    sum[i] = s[0];
  }
  for (int i = 0; i < m; i++) {
    cin >> idx[i];
    idx[i]--;
  }
  build(1, 0, m - 1);
  cout << max(r, mx[1]);
  return 0;
}
