#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
long long arr[N], sums[N], prefix[N], suffix[N], total[N], dp[N], ins[N];
int main() {
  int n, m, l, x;
  scanf("%d %d", &n, &m);
  long long mini, maxi, ans = -1e9;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &l);
    for (int j = 1; j <= l; j++) {
      scanf("%lld", arr + j);
      sums[j] = sums[j - 1] + arr[j];
    }
    total[i] = sums[l];
    maxi = sums[1];
    mini = sums[0];
    ins[i] = -1e9;
    for (int j = 1; j <= l; j++) {
      maxi = max(maxi, sums[j]);
      if (i == l) continue;
      mini = min(mini, sums[j]);
      dp[j] = max((long long)0, dp[j - 1]) + arr[j];
      ins[i] = max(ins[i], dp[j]);
    }
    prefix[i] = maxi;
    suffix[i] = sums[l] - mini;
  }
  long long curr = -1e9;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    ans = max(max(ans, prefix[x]), curr + prefix[x]);
    ans = max(ans, ins[x]);
    curr = max(suffix[x], curr + total[x]);
  }
  cout << ans << endl;
  return 0;
}
