#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 55;
const int M = 250009;
int prefix[N], sum[N], suffix[N], a[N][5009], big[M], q[N];
long long dp[M];
void solve() {
  for (int idx = m; idx >= 0; idx--) {
    int i = big[idx] - 1;
    dp[idx] = max((long long)prefix[i], sum[i] + dp[idx + 1]);
  }
}
int main() {
  long long ans = LLONG_MIN;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    long long ss = 0;
    long long mx = 0;
    int L;
    scanf("%d", &L);
    for (int j = 0; j < L; j++) {
      scanf("%lld", &a[i][j]);
      if (!j) {
        mx = a[i][j];
        ss = a[i][j];
      } else {
        ss += a[i][j];
        mx = max(mx, ss);
      }
    }
    sum[i] = ss;
    prefix[i] = mx;
    ss = 0;
    mx = 0;
    for (int j = L - 1; j >= 0; j--) {
      if (j == L - 1) {
        ss = a[i][j];
        mx = ss;
      } else {
        ss += a[i][j];
        mx = max(mx, ss);
      }
    }
    suffix[i] = mx;
    int mxx = INT_MIN;
    int sum = 0;
    for (int k = 0; k < L; k++) {
      sum += a[i][k];
      mxx = max(mxx, sum);
      if (sum < 0) sum = 0;
    }
    q[i] = mxx;
  }
  for (int i = 0; i < m; i++) scanf("%d", &big[i]);
  solve();
  for (int i = 0; i < m; i++) {
    ans = max(ans, (long long)q[big[i] - 1]);
    ans = max(ans, suffix[big[i] - 1] + dp[i + 1]);
  }
  printf("%lld", ans);
}
