#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 1e4 + 10, sq = 320;
int n, m;
int dpl[N][N], dpr[N][N], dps[N][N], dp[N][M];
vector<int> shelf[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int T;
    cin >> T;
    for (int j = 0; j < T; j++) {
      int a;
      cin >> a;
      shelf[i].push_back(a);
    }
  }
  for (int i = 1; i <= n; i++) {
    int sz = shelf[i].size();
    dpl[i][1] = shelf[i][0];
    dpr[i][1] = shelf[i][sz - 1];
    for (int j = 2; j <= sz; j++) {
      dpl[i][j] = dpl[i][j - 1] + shelf[i][j - 1];
      dpr[i][j] = dpr[i][j - 1] + shelf[i][sz - j];
    }
    dps[i][0] = 0;
    for (int j = 1; j <= sz; j++) {
      for (int k = 0; k <= j; k++)
        dps[i][j] = max(dps[i][j], dpl[i][k] + dpr[i][j - k]);
    }
  }
  dp[0][0] = 0;
  for (int cnt = 0, i = 1; i <= n; i++) {
    int sz = shelf[i].size();
    cnt += sz;
    for (int j = 0; j <= min(m, cnt); j++) {
      for (int k = 0; k <= min(j, sz); k++)
        dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + dps[i][k]);
    }
  }
  cout << dp[n][m];
}
