#테트로미노
#https://www.acmicpc.net/problem/14500
import sys
sys.stdin = open("input.txt","r")
n,m =map(int,input().split())
board=[list(map(int,input().split())) for _ in range(n)]
res=0
tetromino=[ #19가지 테트로미노가 나올 수 있음
    [(0,0),(0,1),(1,0),(1,1)], #ㅁ
    [(0,0),(0,1),(0,2),(0,3)], #ㅡ
    [(0,0),(1,0),(2,0),(3,0)], #ㅣ
    [(0,0),(0,1),(0,2),(1,1)], #ㅜ
    [(0,1),(1,0),(1,1),(1,2)], #ㅗ
    [(0,1),(1,0),(1,1),(2,1)], #ㅓ
    [(0,0),(1,0),(1,1),(2,0)], #ㅏ
    [(0,0),(0,1),(0,2),(1,0)], #긴 기억 모양
    [(0,2),(1,0),(1,1),(1,2)],
    [(0,0),(1,0),(1,1),(1,2)],
    [(0,0),(0,1),(0,2),(1,2)],
    [(0,0),(0,1),(1,1),(2,1)],
    [(0,0),(0,1),(1,0),(2,0)],
    [(0,0),(1,0),(2,0),(2,1)],
    [(0,1),(1,1),(2,0),(2,1)],
    [(0,1),(1,0),(1,1),(2,0)], #번개모양
    [(0,0),(1,0),(1,1),(2,1)],
    [(0,1),(0,2),(1,0),(1,1)],
    [(0,0),(0,1),(1,1),(1,2)]
]

def find(h,w):
    global res
    for i in range(19):
        sum=0
        for j in range(4): #테트로미노 블록이 4개
            try:
                nh=h+tetromino[i][j][0] #x좌표
                nw=w+tetromino[i][j][1] #y좌표
                sum+=board[nh][nw]
            except IndexError:
                continue
        res=max(sum,res)

for i in range(n):
    for j in range(m):
        find(i,j)
        
print(res)
