#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int maxl = 5050;
long long arr[maxn][maxl], len[maxn], n, m;
long long ans[maxl * maxn];
long long prefix[maxn], suffix[maxn], sum[maxn], res[maxn];
void run() {
  for (int e = 0; e < n; e++) {
    prefix[e] = suffix[e] = sum[e] = res[e] = 0;
    long long ans = 0;
    for (int f = 0; f < len[e]; f++) {
      sum[e] += arr[e][f];
      prefix[e] = max(prefix[e], sum[e]);
    }
    for (int f = 0; f < len[e]; f++) {
      ans += arr[e][f];
      res[e] = max(res[e], ans);
      ans = max(ans, 0ll);
    }
    long long s2 = 0;
    for (int f = len[e] - 1; f >= 0; f--) {
      s2 += arr[e][f];
      suffix[e] = max(suffix[e], s2);
    }
  }
}
int main() {
  long long unit = -2000;
  cin >> n >> m;
  for (int e = 0; e < n; e++) {
    cin >> len[e];
    for (int f = 0; f < len[e]; f++) cin >> arr[e][f];
  }
  run();
  long long r = 0, s = 0;
  set<int> q;
  for (int e = 0; e < m; e++) {
    cin >> ans[e];
    ans[e]--;
    q.insert(ans[e]);
    r = max(r, res[ans[e]]);
    r = max(r, s + prefix[ans[e]]);
    s += sum[ans[e]];
    s = max(s, suffix[ans[e]]);
  }
  for (auto &it : q)
    for (int e = 0; e < len[it]; e++) unit = max(arr[it][e], unit);
  if (unit < 0)
    cout << unit << endl;
  else
    cout << r << endl;
  return 0;
}
