package BOJ.BruteForce;
import java.util.Scanner;
public class BOJ_14500 {
static int[][] square;
public static void main(String[] args) {
java.util.Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
square = new int[n + 1][m + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
square[i][j] = sc.nextInt();
}
}
solve(n, m);
}
private static void solve(int n, int m) {
int answer = 0;
int temp = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i + 2 <= n && j + 1 <= m) {
temp = square[i][j] + square[i + 1][j] + square[i + 2][j] + square[i + 2][j + 1];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i + 2][j] + square[i][j + 1] + square[i + 1][j + 1] + square[i + 2][j + 1];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i][j] + square[i][j + 1] + square[i + 1][j + 1] + square[i + 2][j + 1];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i][j] + square[i + 1][j] + square[i + 2][j] + square[i][j + 1];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j] + square[i][j + 1] + square[i][j + 2] + square[i + 1][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j + 2] + square[i + 1][j] + square[i + 1][j + 1] + square[i + 1][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j] + square[i + 1][j] + square[i + 1][j + 1] + square[i + 1][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j] + square[i + 1][j] + square[i][j + 1] + square[i][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j] + square[i][j + 1] + square[i + 1][j + 1] + square[i + 1][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i + 1][j] + square[i + 1][j + 1] + square[i][j + 1] + square[i][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i][j] + square[i + 1][j] + square[i + 1][j + 1] + square[i + 2][j + 1];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i][j + 1] + square[i + 1][j] + square[i + 1][j + 1] + square[i + 2][j];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i][j] + square[i + 1][j] + square[i + 1][j + 1] + square[i + 2][j];
if (answer < temp)
answer = temp;
}
if (i + 2 <= n && j + 1 <= m) {
temp = square[i + 1][j] + square[i][j + 1] + square[i + 1][j + 1] + square[i + 2][j + 1];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j + 1] + square[i + 1][j] + square[i + 1][j + 1] + square[i + 1][j + 2];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 2 <= m) {
temp = square[i][j] + square[i][j + 1] + square[i][j + 2] + square[i + 1][j + 1];
if (answer < temp)
answer = temp;
}
if (j + 3 <= m) {
temp = square[i][j] + square[i][j + 1] + square[i][j + 2] + square[i][j + 3];
if (answer < temp)
answer = temp;
}
if (i + 3 <= n) {
temp = square[i][j] + square[i + 1][j] + square[i + 2][j] + square[i + 3][j];
if (answer < temp)
answer = temp;
}
if (i + 1 <= n && j + 1 <= m) {
temp = square[i][j] + square[i][j + 1] + square[i + 1][j] + square[i + 1][j + 1];
if (answer < temp)
answer = temp;
}
}
}
System.out.println(answer);
}
}