#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, l, j, a;
  long long p[250005], dp[250005], r[55][3], y[55] = {0};
  long long sum, val;
  vector<long long> v[55];
  scanf("%I64d %I64d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &l);
    for (j = 0; j < l; j++) {
      scanf("%I64d", &a);
      v[i].push_back(a);
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%I64d", &p[i]);
    p[i]--;
    y[p[i]] |= 1;
  }
  for (i = 0; i < n; i++) {
    sum = val = v[i][0];
    l = v[i].size();
    for (j = 1; j < l; j++) {
      sum += v[i][j];
      val = max(sum, val);
    }
    r[i][0] = val;
    sum = val = v[i][l - 1];
    for (j = l - 2; j >= 0; j--) {
      sum += v[i][j];
      val = max(sum, val);
      if (0) cout << i << " " << j << " " << val << " " << sum << endl;
    }
    r[i][1] = val;
    r[i][2] = sum;
    if (0)
      cout << i + 1 << " " << r[i][0] << " " << r[i][1] << " " << r[i][2]
           << endl;
  }
  val = r[p[0]][0];
  dp[0] = r[p[0]][1];
  for (i = 1; i < m; i++) {
    val = max(val, dp[i - 1] + r[p[i]][0]);
    dp[i] = max(dp[i - 1] + r[p[i]][2], r[p[i]][1]);
  }
  for (i = 0; i < n; i++) {
    if (!y[i]) continue;
    sum = v[i][0];
    val = max(val, sum);
    l = v[i].size();
    for (j = 1; j < l; j++) {
      sum = max(sum + v[i][j], v[i][j]);
      val = max(val, sum);
    }
  }
  printf("%I64d", val);
  return 0;
}
