#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5100;
int a[MAXN], maxitem[MAXN];
long long l[MAXN], r[MAXN], best[MAXN], sum[MAXN];
int main() {
  int n, m, L;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &L);
    maxitem[i] = -1000000000;
    for (int j = 0; j < L; j++) {
      scanf("%d", &a[j]);
      maxitem[i] = max(maxitem[i], a[j]);
    }
    long long cur = 0, best_left = 0;
    for (int j = 0; j < L; j++) {
      cur += a[j];
      if (cur > best_left) best_left = cur;
    }
    sum[i] = cur;
    cur = 0;
    long long best_right = 0;
    for (int j = L - 1; j >= 0; j--) {
      cur += a[j];
      if (cur > best_right) best_right = cur;
    }
    cur = 0;
    best[i] = 0;
    for (int j = 0; j < L; j++) {
      cur += a[j];
      if (cur < 0) cur = 0;
      if (cur > best[i]) best[i] = cur;
    }
    l[i] = best_left, r[i] = best_right;
  }
  long long cur = 0, res = 0;
  int maxitemArray = -1000000000;
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    x--;
    maxitemArray = max(maxitemArray, maxitem[x]);
    res = max(best[x], res);
    res = max(res, cur + l[x]);
    cur = max(cur + sum[x], r[x]);
    res = max(res, cur);
  }
  if (maxitemArray <= 0) {
    printf("%d\n", maxitemArray);
  } else {
    printf("%lld\n", res);
  }
  return 0;
}
