#include <bits/stdc++.h>
using namespace std;
long long t, n, m, l, res, a[300005], MIN, psum[300005], PSUM[300005],
    Sum[300005], S, x[300005], MAX[300005], Min[300005], MIN1, OK[300005],
    ok[300005], pos, Khac;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  res = (long long)-1e18;
  for (int i = 1; i <= n; i++) {
    cin >> l;
    S = 0;
    PSUM[i] = Min[i] = 0;
    MAX[i] = (long long)-1e18;
    for (int j = 1; j <= l; j++) {
      cin >> a[j];
      S += a[j];
      MAX[i] = max(MAX[i], S - Min[i]);
      Min[i] = min(Min[i], S);
      if (S > psum[i]) ok[i] = 1;
      psum[i] = max(psum[i], S);
      if (S < PSUM[i] && j == l) OK[i] = 1;
      PSUM[i] = min(PSUM[i], S);
    }
    Sum[i] = S;
  }
  S = 0;
  pos = 1;
  Khac = 0;
  for (int i = 1; i <= m; i++) {
    int j;
    cin >> j;
    res = max(res, MAX[j]);
    if (i == 1 && ok[j] == 1) res = max(res, psum[j] + S - MIN);
    if (!(ok[j] == 0 && pos == 1))
      res = max(res, psum[j] + S - MIN);
    else if (Khac == 1)
      res = max(res, psum[j] + S - MIN1);
    if (MIN >= S + PSUM[j]) {
      Khac = 1;
      MIN1 = MIN;
      MIN = min(MIN, S + PSUM[j]);
      pos = OK[j];
    }
    S += Sum[j];
    int khac = 1;
  }
  cout << res;
}
