#include <bits/stdc++.h>
using namespace std;
vector<long long> ars[60];
long long lcss[60];
long long pref[60];
long long suf[60];
long long sum[60];
long long n, m, glo_ans = -1e18;
int main() {
  long long ln, inp;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> ln;
    long long mx = -20000000, curmx = 0, sm1 = 0, sm2 = 0, mxpre = 0, mxsu = 0,
              low = -2000;
    for (int j = 1; j <= ln; ++j) {
      cin >> inp;
      ars[i].push_back(inp);
      sm1 += inp;
      mxpre = max(mxpre, sm1);
      mx = max(mx, inp);
      curmx += inp;
      if (curmx < 0)
        curmx = 0;
      else
        mx = max(mx, curmx);
    }
    for (int j = ln - 1; j >= 0; --j) {
      sm2 += ars[i][j];
      mxsu = max(mxsu, sm2);
    }
    lcss[i] = mx;
    sum[i] = sm1;
    suf[i] = mxsu;
    pref[i] = mxpre;
  }
  long long cur = 0, nol = 0;
  bool del = 0;
  for (int i = 1; i <= m; ++i) {
    cin >> inp;
    glo_ans = max(glo_ans, lcss[inp]);
    if (cur > 0) {
      glo_ans = max(glo_ans, cur + pref[inp]);
    }
    cur = max(nol, max(suf[inp], cur + sum[inp]));
  }
  cout << glo_ans << "\n";
}
