#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> idx;
vector<long long> bestPref, bestSuf, sum, dp;
long long solve(int p) {
  if (p == m) return 0;
  if (dp[p] != -1) return dp[p];
  return dp[p] = max(bestPref[idx[p]], sum[idx[p]] + solve(p + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  dp.resize(m, -1);
  bestPref.resize(n);
  bestSuf.resize(n);
  sum.resize(n);
  idx.resize(m);
  vector<long long> all(n), kadane(n);
  long long ans = LONG_LONG_MIN;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    vector<long long> nums(l);
    for (int j = 0; j < l; j++) cin >> nums[j];
    all[i] = *max_element(nums.begin(), nums.end());
    long long s = 0;
    for (int j = 0; j < l; j++) {
      s += nums[j];
      s = max(s, 0LL);
      kadane[i] = max(kadane[i], s);
    }
    s = 0;
    for (int j = 0; j < l; j++) {
      s += nums[j];
      bestPref[i] = max(bestPref[i], s);
    }
    s = 0;
    for (int j = l - 1; j >= 0; j--) {
      s += nums[j];
      bestSuf[i] = max(bestSuf[i], s);
    }
    sum[i] = s;
  }
  for (int i = 0; i < m; i++) {
    cin >> idx[i];
    idx[i] -= 1;
  }
  long long mx = LONG_LONG_MIN;
  for (int i = 0; i < m; i++) {
    ans = max({ans, solve(i), all[idx[i]], bestSuf[idx[i]] + solve(i + 1),
               kadane[idx[i]]});
    mx = max(mx, all[idx[i]]);
  }
  if (mx < 0) ans = mx;
  cout << ans << endl;
  return 0;
}
