#include <bits/stdc++.h>
using namespace std;
long long INF = 1LL << 62;
int as[59][5009];
long long ls[59];
long long ds[52][4];
int N, M;
vector<int> ms;
void init() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < ls[i]; j++) {
      ds[i][1] += as[i][j];
    }
    long long tmp = 0;
    for (int j = 0; j < ls[i]; j++) {
      tmp += as[i][j];
      ds[i][0] = max(ds[i][0], tmp);
    }
    tmp = 0;
    for (int j = ls[i] - 1; j >= 0; j--) {
      tmp += as[i][j];
      ds[i][2] = max(ds[i][2], tmp);
    }
    long long cont = 0;
    for (int j = 0; j < ls[i]; j++) {
      cont = max(0LL, cont + as[i][j]);
      ds[i][3] = max(ds[i][3], cont);
    }
  }
}
long long solve() {
  long long ans = 0, cont = 0, cur = 0;
  init();
  for (int i = 0; i < ms.size(); i++) {
    int idx = ms[i];
    ans = max(ans, cont + ds[idx][0]);
    ans = max(ans, ds[idx][3]);
    cont = max(0LL, cont + ds[idx][1]);
    cont = max(cont, ds[idx][2]);
  }
  if (ans == 0) {
    sort(ms.begin(), ms.end());
    ms.erase(unique(ms.begin(), ms.end()), ms.end());
    ans = -INF;
    for (int i = 0; i < ms.size(); i++) {
      int id = ms[i];
      for (int j = 0; j < ls[id]; j++) {
        ans = max(ans, (long long)as[id][j]);
      }
    }
    return ans;
  }
  return ans;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    int L;
    scanf("%d", &L);
    ls[i] = L;
    for (int j = 0; j < L; j++) {
      scanf("%d", as[i] + j);
    }
  }
  for (int i = 0; i < M; i++) {
    int x;
    scanf("%d", &x);
    ms.push_back(x - 1);
  }
  cout << solve() << endl;
  return 0;
}
