#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int n, m;
  cin >> n >> m;
  long long sum[50], gen[50], left[50], right[50];
  for (int i = 0; i < n; i++) {
    sum[i] = 0;
    gen[i] = -5000 * 1000;
    left[i] = -5000 * 1000;
    right[i] = 5000 * 1000;
  }
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    long long gs = 0;
    for (int j = 0; j < l; j++) {
      int a;
      cin >> a;
      sum[i] += a;
      gs += a;
      gen[i] = max(gen[i], gs);
      gs = max(gs, 0ll);
      left[i] = max(left[i], sum[i]);
      right[i] = min(right[i], sum[i]);
    }
    right[i] = sum[i] - right[i];
  }
  long long best = -250000ll * 5000ll * 1000ll;
  long long acc = 0;
  while (m--) {
    int i;
    cin >> i;
    i--;
    best = max(max(best, gen[i]), max(acc + left[i], acc + sum[i]));
    acc = max(acc + sum[i], max(right[i], 0ll));
  }
  cout << best << endl;
  return 0;
}
