#include <bits/stdc++.h>
using namespace std;
int n, m;
long long small[55][5005];
long long precomp[55][5];
int big[250005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  long long curr;
  long long best;
  for (int i = 1; i <= n; i++) {
    cin >> small[i][0];
    long long total = 0;
    for (int j = 1; j <= small[i][0]; j++) {
      cin >> small[i][j];
      total += small[i][j];
    }
    precomp[i][0] = total;
    curr = 0;
    best = -1000000;
    for (int j = 1; j <= small[i][0]; j++) {
      curr += small[i][j];
      best = max(best, curr);
      if (curr < 0) curr = 0;
    }
    precomp[i][1] = best;
    curr = 0;
    best = -1000000;
    for (int j = 1; j <= small[i][0]; j++) {
      curr += small[i][j];
      best = max(best, curr);
    }
    precomp[i][2] = best;
    curr = 0;
    best = -1000000;
    for (int j = small[i][0]; j >= 1; j--) {
      curr += small[i][j];
      best = max(best, curr);
    }
    precomp[i][3] = best;
  }
  for (int i = 1; i <= m; i++) cin >> big[i];
  curr = -1000000;
  best = -1000000;
  bool continuing = 0;
  for (int i = 1; i <= m; i++) {
    best = max(best, curr + precomp[big[i]][2]);
    best = max(best, precomp[big[i]][1]);
    curr = max(curr + precomp[big[i]][0], precomp[big[i]][3]);
    best = max(best, curr);
  }
  cout << best << '\n';
  return 0;
}
