#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 60);
int n, m;
long long lmax[50], rmax[50], sum[50], mx[50];
int b[250000];
bool use[50];
void run() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int len, a[5000];
    scanf("%d", &len);
    for (int j = 0; j < len; j++) scanf("%d", a + j);
    lmax[i] = rmax[i] = mx[i] = -inf;
    long long s = 0, t = 0, u = 0;
    for (int j = 0; j < len; j++) {
      s += a[j];
      t += a[len - 1 - j];
      lmax[i] = max(lmax[i], s);
      rmax[i] = max(rmax[i], t);
      u = max((long long)a[j], u + a[j]);
      mx[i] = max(mx[i], u);
    }
    sum[i] = s;
  }
  for (int i = 0; i < n; i++) use[i] = 0;
  for (int i = 0; i < m; i++) scanf("%d", b + i), use[--b[i]] = 1;
  long long ans = -inf, s = rmax[b[0]];
  for (int i = 0; i < n; i++)
    if (use[i]) ans = max(ans, mx[i]);
  ans = max(ans, max(lmax[b[0]], rmax[b[0]]));
  for (int i = 1; i < m; i++) {
    ans = max(ans, s + lmax[b[i]]);
    s = max(rmax[b[i]], s + sum[b[i]]);
  }
  cout << ans << endl;
}
int main() {
  run();
  return 0;
}
