#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int isGreater(long double x, long double y) {
  if (abs(x - y) < eps) return 0;
  if (x > y) return 1;
  return -1;
}
struct SumInfo {
  int arraySum, maxPre, maxSuff, maxSum;
  SumInfo() {
    arraySum = 0;
    maxPre = maxSuff = maxSum = INT_MIN / 2;
  }
};
SumInfo calcInfo(const vector<int> &a) {
  int running_sum = 0;
  SumInfo ret;
  for (int x : a) {
    if (running_sum < 0) running_sum = 0;
    running_sum += x;
    ret.arraySum += x;
    ret.maxSum = max(ret.maxSum, running_sum);
    ret.maxPre = max(ret.maxPre, ret.arraySum);
  }
  running_sum = 0;
  for (int i = (int)((a).size()) - 1; i >= 0; --i) {
    running_sum += a[i];
    ret.maxSuff = max(ret.maxSuff, running_sum);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > arr(n);
  for (int i = 0; i < n; ++i) {
    int l;
    cin >> l;
    arr[i].resize(l);
    for (int j = 0; j < l; ++j) cin >> arr[i][j];
  }
  vector<int> ind(m);
  for (int i = 0; i < m; ++i) cin >> ind[i], --ind[i];
  vector<SumInfo> info(n);
  for (int i = 0; i < n; ++i) info[i] = calcInfo(arr[i]);
  long long best = LLONG_MIN, bestPrev = 0;
  for (int i : ind) {
    if (bestPrev < 0) bestPrev = 0;
    best = max(best, 1LL * info[i].maxSum);
    best = max(best, bestPrev + info[i].maxPre);
    bestPrev = max(1LL * info[i].maxSuff, bestPrev + info[i].arraySum);
  }
  cout << best << '\n';
}
