#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int Max = 1000;
int main() {
  int n, m;
  cin >> n >> m;
  long long arr[n][5001];
  int lens[n];
  long long sumarr[n];
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    lens[i] = l;
    long long sum = 0;
    for (int j = 0; j < l; j++) {
      cin >> arr[i][j];
      sum += arr[i][j];
    }
    sumarr[i] = sum;
  }
  long long bigarr[m];
  for (int i = 0; i < m; i++) {
    cin >> bigarr[i];
  }
  long long ans = INT64_MIN;
  long long start[n];
  long long ends[n];
  long long ps[n];
  for (int i = 0; i < n; i++) {
    long long sum = 0, max_sum = INT64_MIN, st = 0, en = 0, s = 0;
    int l = lens[i];
    for (int j = 0; j < l; j++) {
      sum += arr[i][j];
      if (sum > max_sum) {
        max_sum = sum;
        st = s;
        en = i;
      }
      if (sum <= 0) {
        sum = 0;
        s = i + 1;
      }
    }
    ps[i] = max_sum;
    sum = 0;
    int ind = -1;
    long long m = 0;
    for (int j = 0; j < l; j++) {
      sum += arr[i][j];
      if (sum > m) {
        m = sum;
        ind = j;
      }
    }
    start[i] = m;
    sum = 0;
    ind = -1;
    m = 0;
    for (int j = l - 1; j >= 0; j--) {
      sum += arr[i][j];
      if (sum > m) {
        m = sum;
        ind = j;
      }
    }
    ends[i] = m;
  }
  for (int i = 0; i < m; i++) {
    ans = max(ans, ps[bigarr[i] - 1]);
  }
  int i = 0;
  while (i < m && ends[bigarr[i] - 1] == 0) {
    i++;
  }
  if (i == m) {
    if (ans != INT64_MIN)
      cout << ans << endl;
    else {
      for (int i = 0; i < n; i++) {
        ans = max(ans, *max_element(arr[i], arr[i] + lens[i]));
      }
      cout << ans << endl;
    }
  } else {
    long long cur_sum = 0;
    for (int i = 0; i < m; i++) {
      long long a = cur_sum + sumarr[bigarr[i] - 1];
      long long b = INT64_MIN;
      if (start[bigarr[i] - 1] != 0) b = cur_sum + start[bigarr[i] - 1];
      long long c = ends[bigarr[i] - 1];
      ans = max(ans, b);
      if (c > a) {
        cur_sum = c;
        ans = max(ans, cur_sum);
      } else {
        cur_sum = a;
        ans = max(ans, cur_sum);
      }
    }
    cout << ans << endl;
  }
}
