#include <bits/stdc++.h>
using namespace std;
pair<vector<pair<int, int>>, long long> solve(vector<long long> a) {
  vector<pair<int, int>> ret;
  long long max_cur = a[0], max_global = a[0];
  for (int i = 1; i < (int)a.size(); ++i) {
    max_cur = max(a[i], a[i] + max_cur);
    max_global = max(max_global, max_cur);
  }
  int l = 0, r = 0;
  max_cur = a[0];
  if (max_cur == max_global) {
    ret.push_back({l, r});
  }
  for (int i = 1; i < (int)a.size(); ++i) {
    r = i;
    if (a[i] > a[i] + max_cur) {
      l = i;
    }
    max_cur = max(a[i], a[i] + max_cur);
    if (max_global == max_cur) ret.push_back({l, r});
  }
  return {ret, max_global};
}
struct element {
  long long l, r, total, best;
  element() { l = r = total = best = 0; }
  element(long long l, long long r, long long total, long long best) {
    this->l = l;
    this->r = r;
    this->total = total;
    this->best = best;
  }
};
long long solveLeft(vector<long long> a) {
  long long ret = a[0], cum = a[0];
  for (int i = 1; i < (int)a.size(); ++i) {
    cum += a[i];
    ret = max(ret, cum);
  }
  return ret;
}
long long solveRight(vector<long long> a) {
  reverse(a.begin(), a.end());
  return solveLeft(a);
}
const int N = 250001;
long long dp[N][2];
long long OO = -1e15;
int n, m;
vector<element> bigArray;
long long solve(int idx, bool state) {
  if (idx == m) return (!state) * OO;
  long long &ret = dp[idx][state];
  if (ret != OO) return ret;
  if (!state)
    ret = max(ret, max(bigArray[idx].r + solve(idx + 1, 1), solve(idx + 1, 0)));
  return ret = max(ret, max(bigArray[idx].l,
                            bigArray[idx].total + solve(idx + 1, 1)));
}
int main() {
  for (int i = 0; i < N; ++i) dp[i][0] = dp[i][1] = OO;
  scanf("%d%d", &n, &m);
  vector<vector<long long>> arrays(n);
  vector<element> elements(n);
  for (int i = 0; i < n; ++i) {
    int l;
    scanf("%d", &l);
    arrays[i].resize(l);
    long long sum = 0;
    for (int j = 0; j < l; ++j) {
      scanf("%lld", &arrays[i][j]);
      sum += arrays[i][j];
    }
    elements[i] = element(solveLeft(arrays[i]), solveRight(arrays[i]), sum,
                          solve(arrays[i]).second);
  }
  long long ans = OO;
  bigArray.resize(m);
  for (int i = 0; i < m; ++i) {
    int idx;
    scanf("%d", &idx);
    bigArray[i] = elements[idx - 1];
    ans = max(ans, elements[idx - 1].best);
  }
  printf("%lld\n", max(ans, solve(0, 0)));
  return 0;
}
