#include <bits/stdc++.h>
using namespace std;
int sum[55];
int Max[55];
int End[55];
int MaxCurrent[55];
int biggest[55];
int arr[5005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int l;
    scanf("%d", &l);
    int c = 0;
    biggest[i] = -1000;
    for (int j = 1; j <= l; j++) {
      scanf("%d", arr + j);
      biggest[i] = max(biggest[i], arr[j]);
      sum[i] += arr[j];
      c += arr[j];
      if (c < 0) c = 0;
      MaxCurrent[i] = max(MaxCurrent[i], c);
      Max[i] = max(Max[i], sum[i]);
    }
    c = 0;
    for (int j = l; j >= 1; j--) {
      c += arr[j];
      End[i] = max(End[i], c);
    }
  }
  long long ans = 0;
  long long have = 0;
  int ee = -1000;
  for (int i = 1; i <= m; i++) {
    int a;
    scanf("%d", &a);
    ee = max(ee, biggest[a]);
    ans = max(ans, have + Max[a]);
    ans = max(ans, (long long)MaxCurrent[a]);
    have = max(have + sum[a], (long long)End[a]);
  }
  if (ee <= 0)
    printf("%d", ee);
  else
    printf("%I64d", ans);
  return 0;
}
