#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int m, n;
int a[50][50], f[50][50];
int main() {
freopen("teacher.in", "r", stdin);
freopen("teacher.out", "w", stdout);
scanf("%d%d", &m, &n);
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= m; i++)
for (int j = n; j >= 0; j--) {
f[i][j] = f[i-1][j];
for (int k = 1; k <= j; k++)
f[i][j] = max(f[i][j], f[i-1][j-k] + a[i][k]);
}
// for (int i = 1; i <= m; i++) {
// for (int j = 1; j <= n; j++) printf("%d ", f[i][j]); printf("\n"); }
printf("%d", f[m][n]);
return 0;
}