#include <bits/stdc++.h>
using namespace std;
int n, m, l[55], r[250005], a[55][4];
long long temp, out;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
    a[i][0] = 0;
    for (int j = 0; j < l[i]; j++) {
      scanf("%d", &r[j]);
      a[i][0] += r[j];
    }
    a[i][1] = r[0];
    for (int j = 0, s = 0; j < l[i]; j++) {
      s += r[j];
      a[i][1] = max(a[i][1], s);
    }
    a[i][2] = r[0];
    for (int j = 0, s = 0; j < l[i]; j++) {
      s += r[j];
      a[i][2] = max(a[i][2], s);
      if (s < 0) s = 0;
    }
    a[i][3] = r[l[i] - 1];
    for (int j = l[i] - 1, s = 0; j >= 0; j--) {
      s += r[j];
      a[i][3] = max(a[i][3], s);
    }
  }
  temp = 0;
  out = -1000000000000000LL;
  for (int i = 0; i < m; i++) {
    scanf("%d", &r[i]);
    r[i]--;
    out = max(out, max(temp + a[r[i]][1], (long long)a[r[i]][2]));
    temp = max(temp + a[r[i]][0], (long long)a[r[i]][3]);
    if (temp < 0) temp = 0;
  }
  cout << out << endl;
  return 0;
}
