#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> p[110];
int dp1[110][110];
int dp[110][10010];
void pro(int x, int y) {
  int r = 0;
  for (int i = 0; i < y; i++) {
    r += p[x][i];
  }
  dp1[x][y] = r;
  int en = p[x].size() - 1;
  for (int i = y - 1; i >= 0; i--) {
    r -= p[x][i];
    r += p[x][en--];
    dp1[x][y] = max(dp1[x][y], r);
  }
}
int f(int i, int m) {
  if (i == n) return 0;
  if (dp[i][m] != -1) return dp[i][m];
  int r = 0;
  for (int j = 0; j <= min(m, (int)p[i].size()); j++) {
    r = max(r, dp1[i][j] + f(i + 1, m - j));
  }
  return dp[i][m] = r;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> y;
    for (int j = 0; j < y; j++) {
      cin >> x;
      p[i].push_back(x);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= p[i].size(); j++) {
      pro(i, j);
    }
  }
  memset(dp, -1, sizeof dp);
  cout << f(0, m) << endl;
  return 0;
}
