#include<cstdio>
#include<utility>
using namespace std;
const int M = 555;
const int MM = 19;
int imap[M][M];
struct pos {
int r, c;
};
// 이렇게 하면 안될거같은데
pos check[MM][4] = {
{ {0,0}, {1,0}, {0,1}, {1,1} },
{ {0,0}, {0,1}, {0,2}, {0,3} },
{ {0,0}, {1,0}, {2,0}, {3,0} },
{ {0,0}, {1,0}, {1,1}, {2,1} },
{ {0,0}, {0,1}, {1,1}, {1,2} },
{ {1,0}, {1,1}, {0,1}, {0,2}},
{ {0,1}, {1,1}, {1,0}, {2,0} },
{ {0,1}, {1,0}, {1,1}, {1,2} },
{ {0,0}, {0,1}, {0,2}, {1,1} },
{ {0,1}, {1,0}, {1,1}, {2,1} },
{ {0,0}, {1,0}, {1,1}, {2,0} },
{ {0,0}, {0,1}, {0,2}, {1,2} },
{ {0,1}, {1,1}, {2,1}, {2,0} },
{ {1,0}, {1,1}, {1,2}, {0,2} },
{ {0,0}, {0,1}, {1,0}, {2,0} },
{ {0,0}, {0,1}, {0,2}, {1,0} },
{ {0,0}, {1,0}, {2,0}, {2,1} },
{ {0,0}, {1,0}, {1,1}, {1,2} },
{ {0,0}, {0,1}, {1,1}, {2,1} },
};
int main() {
int row, col;
scanf("%d%d", &row, &col);
for (int r = 0; r < row; r++) {
for (int c = 0; c < col; c++) {
scanf("%d",&imap[r][c]);
}
}
int ans = 0;
for (int r = 0; r < row; r++) {
for (int c = 0; c < col; c++) {
for (int i = 0; i < MM; i++) {
int res = 0;
for (int bn = 0; bn < 4; bn++) {
int tr = r + check[i][bn].r;
int tc = c + check[i][bn].c;
res += imap[tr][tc];
}
ans = (ans > res) ? ans : res;
}
}
}
printf("%d\n", ans);
return 0;
}