#include <bits/stdc++.h>
using namespace std;
const int N = 250005;
int idx[N];
vector<int> adj[55];
long long tot[55], prefix[55], suffix[55], best[55];
int n, m;
long long solve(int cur) {
  long long ret = adj[cur][0], sum = 0;
  for (int i = 0; i < int(int(adj[cur].size())); i++) {
    sum += adj[cur][i];
    ret = max(ret, sum);
    if (sum < 0) sum = 0;
  }
  return ret;
}
int main() {
  long long ans = -1e18;
  int l, x;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < int(n); i++) {
    scanf("%d", &l);
    adj[i].resize(l);
    for (int j = 0; j < int(l); j++) {
      scanf("%d", &adj[i][j]);
      tot[i] += adj[i][j];
      if (!j)
        prefix[i] = tot[i];
      else
        prefix[i] = max(prefix[i], tot[i]);
    }
    long long c = 0;
    for (int j = int(l - 1); j >= 0; j--) {
      c += adj[i][j];
      suffix[i] = max(suffix[i], c);
    }
    best[i] = solve(i);
  }
  for (int i = 0; i < int(m); i++) {
    scanf("%d", &idx[i]);
    idx[i]--;
    ans = max(ans, best[idx[i]]);
  }
  long long sum = suffix[idx[0]];
  for (int i = int(1); i <= int(m - 1); i++) {
    ans = max(ans, sum + prefix[idx[i]]);
    sum += tot[idx[i]];
    ans = max(ans, sum);
    sum = max(sum, suffix[idx[i]]);
  }
  cout << ans << endl;
  return 0;
}
