#include <bits/stdc++.h>
using namespace std;
int n, m, l, idx;
int a[5000];
int head[50], tail[50], maxm[50], sum[50];
int main() {
  cin >> n >> m;
  for (int k = 0; k < n; ++k) {
    cin >> l;
    head[k] = -100000000;
    tail[k] = -100000000;
    maxm[k] = -100000000;
    int s = 0;
    int h = 0;
    int t = 0;
    int opt = -100000000;
    for (int i = 0; i < l; ++i) {
      cin >> a[i];
      s += a[i];
      opt = max(opt + a[i], a[i]);
      maxm[k] = max(opt, maxm[k]);
      h += a[i];
      head[k] = max(h, head[k]);
    }
    for (int i = l - 1; i >= 0; --i) {
      t += a[i];
      tail[k] = max(t, tail[k]);
    }
    sum[k] = s;
  }
  long long t = -10000000000000000;
  long long ans = t;
  for (int i = 0; i < m; ++i) {
    cin >> idx;
    --idx;
    if (maxm[idx] > ans) ans = maxm[idx];
    if (t + head[idx] > ans) ans = t + head[idx];
    if (tail[idx] > t + sum[idx])
      t = tail[idx];
    else
      t += sum[idx];
  }
  cout << ans << "\n";
}
