import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] arr = br.readLine().split(" ");
int n = Integer.parseInt(arr[0]);
int m = Integer.parseInt(arr[1]);
int[][] paper = new int[n+1][m+1];
int temp = 0;
int ans = 0;
for(int i=1; i<=n; i++) {
String[] s = br.readLine().split(" ");
for(int j=1; j<=m; j++) { paper[i][j] = Integer.parseInt(s[j-1]); }
}
//blue: 1*4
for(int i=1; i<=n; i++) {
for(int j=1; j<=m-3; j++) {
temp = paper[i][j]+paper[i][j+1]+paper[i][j+2]+paper[i][j+3];
ans = Math.max(ans, temp);
}
}
//blue: 4*1
for(int i=1; i<=n-3; i++) {
for(int j=1; j<=m; j++) {
temp = paper[i][j]+paper[i+1][j]+paper[i+2][j]+paper[i+3][j];
ans = Math.max(ans, temp);
}
}
//yellow
for(int i=1; i<=n-1; i++) {
for(int j=1; j<=m-1; j++) {
temp = paper[i][j]+paper[i+1][j]+paper[i][j+1]+paper[i+1][j+1];
ans = Math.max(ans, temp);
}
}
//pink: 위&아래
for(int i=1; i<=n-1; i++) {
for(int j=1; j<=m-2; j++) {
temp = paper[i][j+1]+paper[i+1][j]+paper[i+1][j+1]+paper[i+1][j+2];
ans = Math.max(ans, temp);
temp = paper[i][j]+paper[i][j+1]+paper[i][j+2]+paper[i+1][j+1];
ans = Math.max(ans, temp);
}
}
//pink: 오른쪽&왼쪽
for(int i=1; i<=n-2; i++) {
for(int j=1; j<=m-1; j++) {
temp = paper[i][j]+paper[i+1][j]+paper[i+1][j+1]+paper[i+2][j];
ans = Math.max(ans, temp);
temp = paper[i][j+1]+paper[i+1][j]+paper[i+1][j+1]+paper[i+2][j+1];
ans = Math.max(ans, temp);
}
}
//green : 1&2
for(int i=1; i<=n-2; i++) {
for(int j=1; j<=m-1; j++) {
temp = paper[i][j]+paper[i+1][j]+paper[i+1][j+1]+paper[i+2][j+1];
ans = Math.max(ans, temp);
temp = paper[i][j+1]+paper[i+1][j]+paper[i+1][j+1]+paper[i+2][j];
ans = Math.max(ans, temp);
}
}
//green : 3&4
for(int i=1; i<=n-1; i++) {
for(int j=1; j<=m-2; j++) {
temp = paper[i+1][j]+paper[i+1][j+1]+paper[i][j+1]+paper[i][j+2];
ans = Math.max(ans, temp);
temp = paper[i][j]+paper[i][j+1]+paper[i+1][j+1]+paper[i+1][j+2];
ans = Math.max(ans, temp);
}
}
//orange: 1&2&3&4
for(int i=1; i<=n-2; i++) {
for(int j=1; j<=m-1; j++) {
temp = paper[i][j]+paper[i+1][j]+paper[i+2][j]+paper[i+2][j+1];
ans = Math.max(ans, temp);
temp = paper[i][j]+paper[i+1][j]+paper[i+2][j]+paper[i][j+1];
ans = Math.max(ans, temp);
temp = paper[i][j+1]+paper[i+1][j+1]+paper[i+2][j+1]+paper[i+2][j];
ans = Math.max(ans, temp);
temp = paper[i][j]+paper[i][j+1]+paper[i+1][j+1]+paper[i+2][j+1];
ans = Math.max(ans, temp);
}
}
//orange: 5&6&7&8
for(int i=1; i<=n-1; i++) {
for(int j=1; j<=m-2; j++) {
temp = paper[i][j]+paper[i+1][j]+paper[i][j+1]+paper[i][j+2];
ans = Math.max(ans, temp);
temp = paper[i][j]+paper[i][j+1]+paper[i][j+2]+paper[i+1][j+2];
ans = Math.max(ans, temp);
temp = paper[i][j]+paper[i+1][j]+paper[i+1][j+1]+paper[i+1][j+2];
ans = Math.max(ans, temp);
temp = paper[i+1][j]+paper[i+1][j+1]+paper[i+1][j+2]+paper[i][j+2];
ans = Math.max(ans, temp);
}
}
System.out.println(ans);
}
}