#include <bits/stdc++.h>
using namespace std;
const int MAXn = 50, MAXl = 5000;
long long Min[MAXn + 2], Max[MAXn + 2], best[MAXn + 2];
vector<long long> ps[MAXn + 2];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, num;
    scanf("%d%d", &l, &num);
    ps[i].push_back(num);
    long long Mini = 0;
    best[i] = num;
    Max[i] = num;
    Mini = min(Mini, (long long)num);
    for (int j = 1; j < l; j++) {
      scanf("%d", &num);
      ps[i].push_back(ps[i][j - 1] + num);
      best[i] = max(best[i], ps[i][j] - Mini);
      Mini = min(ps[i][j], Mini);
      Max[i] = max(Max[i], ps[i][j]);
    }
    Min[i] = Mini;
  }
  long long Maxi = LLONG_MIN, min_ps = LLONG_MAX, sum = 0;
  for (int i = 0; i < m; i++) {
    int ind;
    scanf("%d", &ind);
    ind--;
    Maxi = max(Maxi, best[ind]);
    if (i > 0) Maxi = max(Maxi, Max[ind] + sum - min_ps);
    min_ps = min(min_ps, sum + Min[ind]);
    sum += ps[ind][ps[ind].size() - 1];
  }
  cout << Maxi << endl;
  return 0;
}
