#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 10005;
vector<int> bst[N], item[N];
int dp[N][N][N];
void f(int x) {
  memset(dp, -0x3f, sizeof dp);
  int n = item[x].size();
  dp[0][0][n - 1] = 0;
  for (int i = 1; i < n; ++i) {
    int ans = 0;
    for (int j = 0; j < n; ++j)
      for (int k = j; k < n; ++k) {
        if (j > 0) dp[i][j][k] = dp[i - 1][j - 1][k] + item[x][j - 1];
        if (k < n - 1)
          dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k + 1] + item[x][k + 1]);
        ans = max(ans, dp[i][j][k]);
      }
    bst[x].push_back(ans);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans = max(ans, dp[n - 1][i][i] + item[x][i]);
  bst[x].push_back(ans);
}
int cur[M], nxt[M];
int main() {
  memset(cur, -0x3f, sizeof cur);
  cur[0] = 0;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < x; ++j) {
      int y;
      scanf("%d", &y);
      item[i].push_back(y);
    }
  }
  for (int i = 0; i < n; ++i) {
    f(i);
    memcpy(nxt, cur, sizeof nxt);
    for (int j = 0; j < bst[i].size(); ++j)
      for (int k = 0; k < m - j; ++k)
        nxt[k + j + 1] = max(nxt[k + j + 1], cur[k] + bst[i][j]);
    memcpy(cur, nxt, sizeof cur);
  }
  printf("%d\n", cur[m]);
  return 0;
}
