#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, j, ans = INT_MIN, sum, sum2, y;
  cin >> n >> m;
  vector<long long> pre(n, INT_MIN), suff(n, INT_MIN), kd(n, INT_MIN),
      full(n, INT_MIN);
  for (i = 0; i < n; i++) {
    long long l;
    cin >> l;
    vector<long long> v(l);
    sum = 0;
    sum2 = 0;
    for (j = 0; j < l; j++) {
      cin >> v[j];
      sum += v[j];
      sum2 += v[j];
      kd[i] = max(sum2, kd[i]);
      if (sum2 < 0) sum2 = 0;
      pre[i] = max(pre[i], sum);
    }
    full[i] = sum;
    sum = 0;
    for (j = l - 1; j >= 0; j--) {
      sum += v[j];
      suff[i] = max(suff[i], sum);
    }
  }
  sum = 0;
  for (i = 0; i < m; i++) {
    cin >> y;
    if (sum) ans = max(ans, sum + pre[y - 1]);
    sum = max(0LL, max(sum + full[y - 1], suff[y - 1]));
    if (sum < 0) sum = 0;
    ans = max(ans, kd[y - 1]);
  }
  cout << ans;
}
