#include <bits/stdc++.h>
using namespace std;
long long Set(long long N, long long pos) { return N = N | (1 << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
void CI(long long &_x) { scanf("%d", &_x); }
void CO(long long &_x) { cout << _x; }
template <typename T>
void getarray(T a[], long long n) {
  for (long long i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void prLLIarray(T a[], long long n) {
  for (long long i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const long long INF = 0x7f7f7f7f;
long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
long long dr4[4] = {0, 0, 1, -1};
long long dc4[4] = {-1, 1, 0, 0};
long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
vector<long long> V[55];
long long L[55], R[55];
long long mx_sum[55], sum[55];
int main() {
  for (int i = 0; i < 55; i++)
    mx_sum[i] = -1 << 30, L[i] = -1 << 30, R[i] = -1 << 30;
  long long n, m, temp;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    long long sz;
    cin >> sz;
    for (long long j = 0; j < sz; j++) {
      long long val;
      cin >> val;
      V[i].push_back(val);
    }
  }
  for (long long i = 1; i <= n; i++) {
    long long l_s = 0, second = 0;
    for (long long j = 0; j < V[i].size(); j++) {
      sum[i] += V[i][j];
      mx_sum[i] = max(mx_sum[i], V[i][j]);
      l_s += V[i][j];
      L[i] = max(l_s, L[i]);
      second += V[i][j];
      if (second < 0)
        second = 0;
      else
        mx_sum[i] = max(mx_sum[i], second);
    }
    long long r_s = 0;
    for (long long j = V[i].size() - 1; j >= 0; j--) {
      r_s += V[i][j];
      R[i] = max(R[i], r_s);
    }
  }
  long long ans = 0, result = -1 << 30;
  for (long long i = 1; i <= m; i++) {
    long long inx;
    cin >> inx;
    result = max(result, ans + L[inx]);
    result = max(result, mx_sum[inx]);
    ans = max(ans + sum[inx], R[inx]);
    if (ans < 0)
      ans = 0;
    else
      result = max(ans, result);
  }
  cout << result << "\n";
}
