#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void PLAY() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct val {
  long long mx_left;
  long long mx_right;
  long long tot_sum;
  long long best;
  val() { mx_left = mx_right = tot_sum = best = 0; }
};
val a[55];
long long calc_best(vector<int> &v) {
  long long mx = INT_MIN;
  long long sum = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    mx = max(mx, (long long)v[i]);
    sum += v[i];
    if (sum < 0)
      sum = 0;
    else
      mx = max(sum, mx);
  }
  return mx;
}
long long calc_left(vector<int> &v) {
  long long ret = INT_MIN;
  long long sum = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    sum += v[i];
    ret = max(ret, sum);
  }
  return ret;
}
long long calc_right(vector<int> &v) {
  long long ret = INT_MIN;
  long long sum = 0;
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    sum += v[i];
    ret = max(ret, sum);
  }
  return ret;
}
long long calc_sum(vector<int> &v) {
  long long sum = 0;
  for (int i = 0; i < (int)v.size(); i++) sum += v[i];
  return sum;
}
int idx[250005];
int main() {
  PLAY();
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    v[i].resize(l);
    for (int j = 0; j < l; j++) cin >> v[i][j];
  }
  for (int i = 0; i < m; i++) {
    cin >> idx[i];
    idx[i]--;
  }
  long long res = INT_MIN;
  for (int i = 0; i < n; i++) {
    a[i].best = calc_best(v[i]);
    a[i].mx_left = calc_left(v[i]);
    a[i].mx_right = calc_right(v[i]);
    a[i].tot_sum = calc_sum(v[i]);
  }
  long long sum = 0;
  for (int i = 0; i < m; i++) {
    res = max(res, a[idx[i]].best);
    if (sum) res = max(res, sum + a[idx[i]].mx_left);
    sum = max(0ll, max(a[idx[i]].mx_right, sum + a[idx[i]].tot_sum));
  }
  cout << res << endl;
  return 0;
}
