#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int maxn = 1e3 + 10;
int bag[maxn][maxn];
int t[maxn], a[maxn][maxn];
int dp[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    for (int j = 1; j <= t[i]; j++) {
      cin >> a[i][j];
      a[i][j] += a[i][j - 1];
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= t[i]; j++)
      for (int k = 0; k <= j; k++)
        bag[i][j] = max(bag[i][j], a[i][k] + a[i][t[i]] - a[i][t[i] - (j - k)]);
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 0; j--)
      for (int k = 0; k <= j && k <= t[i]; k++)
        dp[j] = max(dp[j], dp[j - k] + bag[i][k]);
  cout << dp[m] << endl;
}
