#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 1 << 31 - 1;
const long long i64_inf = 1ll << 63 - 1;
const double pi = acos(-1.0);
using namespace std;
int n, m;
int big[350000];
int a[60][6000];
int sum[60];
int max_pref[60];
int min_pref[60];
int Max[60];
int l[60];
long long answer[60];
bool was[60];
int main() {
  cin >> n >> m;
  memset(was, 0, sizeof was);
  for (int i = 0; i < (int)n; i++) {
    int l;
    scanf("%d", &l);
    sum[i] = 0;
    for (int j = 0; j < (int)l; j++)
      scanf("%d", &a[i][j]), sum[i] += a[i][j], was[i] |= a[i][j] > 0;
    int second = 0;
    min_pref[i] = max_pref[i] = 0;
    for (int j = 0; j < (int)l; j++)
      second += a[i][j], max_pref[i] = max(max_pref[i], second),
                         min_pref[i] = min(min_pref[i], second);
    Max[i] = a[i][0];
    for (int j = 0; j < (int)l; j++) Max[i] = max(Max[i], a[i][j]);
    long long S = a[i][0];
    long long MinS = 0;
    answer[i] = S;
    for (int j = 0; j < (int)l; j++) {
      answer[i] = max(answer[i], S - MinS);
      MinS = min(MinS, S);
      S += a[i][j + 1];
    }
  }
  for (int i = 0; i < (int)m; i++) scanf("%d", &big[i]), big[i]--;
  long long S = sum[big[0]];
  long long MinS = min(0, min_pref[big[0]]);
  long long ans = a[big[0]][0];
  bool Was = 0;
  for (int i = 0; i < (int)m; i++) {
    Was |= was[big[i]];
    ans = max(ans, answer[big[i]]);
    long long res = S - MinS;
    if (i != m - 1) res += max_pref[big[i + 1]];
    ans = max(ans, res);
    MinS = min(MinS, S + min_pref[big[i + 1]]);
    S += sum[big[i + 1]];
  }
  if (!Was) {
    ans = a[big[0]][0];
    for (int i = 0; i < (int)m; i++) {
      long long ma = Max[big[i]];
      ans = max(ans, ma);
    }
  }
  cout << ans << endl;
  return 0;
}
