#include <bits/stdc++.h>
using namespace std;
int n, m, mx[59], pref[59], suff[59], sum[59], a[5009];
long long ans = -1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int l;
    cin >> l;
    int temp = 0;
    mx[i] = pref[i] = suff[i] = -1e9;
    for (int j = 1; j <= l; ++j) {
      cin >> a[j];
      sum[i] += a[j];
      pref[i] = max(pref[i], sum[i]);
      temp += a[j];
      temp = max(temp, a[j]);
      mx[i] = max(mx[i], temp);
    }
    temp = 0;
    for (int j = l; j >= 1; --j) {
      temp += a[j];
      suff[i] = max(suff[i], temp);
    }
  }
  long long temp = 0;
  while (m--) {
    int b;
    cin >> b;
    ans = max(ans, max((long long)mx[b], pref[b] + temp));
    temp = max(max(temp + sum[b], (long long)suff[b]), 0LL);
  }
  cout << ans;
  return 0;
}
