#include <stdio.h>
const int MAX = 50;
const int MAX_D = 4;
const int DOWN = 0, LEFT = 1, RIGHT = 2;
int G[MAX][MAX];
int M[MAX][MAX][MAX * MAX][3];
int n, m;
int max (int a, int b) { return a > b ? a : b; }
int f(int i, int j, int p, int d) {
if (i == n || j == n || j < 0 || p == m)
return 0;
if (M[i][j][p][d] != -1) return M[i][j][p][d];
int ret = 0;
if (d == DOWN) {
ret = max(ret, f(i + 1, j, p + 1, DOWN));
ret = max(ret, f(i, j - 1, p + 1, RIGHT));
ret = max(ret, f(i, j + 1, p + 1, LEFT));
} else if (d == LEFT) {
ret = max(ret, f(i + 1, j, p + 1, DOWN));
ret = max(ret, f(i, j + 1, p + 1, LEFT));
} else {
ret = max(ret, f(i + 1, j, p + 1, DOWN));
ret = max(ret, f(i, j - 1, p + 1, RIGHT));
}
return M[i][j][p][d] = ret + G[i][j];
}
int main()
{
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
for (int p = 0; p < MAX * MAX; p++)
for (int d = 0; d < MAX_D; d++)
M[i][j][p][d] = -1;
G[i][j] = 0;
}
}
scanf ("%d %d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
scanf ("%d", &G[i][j]);
printf ("%d\n", f(0, 0, 0, DOWN));
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpjb25zdCBpbnQgTUFYICAgPSA1MDsKY29uc3QgaW50IE1BWF9EID0gNDsKY29uc3QgaW50IERPV04gPSAwLCBMRUZUID0gMSwgUklHSFQgPSAyOwoKaW50IEdbTUFYXVtNQVhdOwppbnQgTVtNQVhdW01BWF1bTUFYICogTUFYXVszXTsKaW50IG4sIG07CgppbnQgbWF4IChpbnQgYSwgaW50IGIpIHsgcmV0dXJuIGEgPiBiID8gYSA6IGI7IH0KCmludCBmKGludCBpLCBpbnQgaiwgaW50IHAsIGludCBkKSB7CglpZiAoaSA9PSBuIHx8IGogPT0gbiB8fCBqIDwgMCB8fCBwID09IG0pC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