import sys
n, m = map(int, sys.stdin.readline().split())
board = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
blocks = [
[(0, 1), (1, 0), (1, 1)],
[(0, 1), (0, 2), (0, 3)],
[(1, 0), (2, 0), (3, 0)],
[(0, 1), (0, 2), (1, 0)],
[(0, 1), (0, 2), (-1, 2)],
[(1, 0), (1, 1), (1, 2)],
[(0, 1), (0, 2), (1, 2)],
[(1, 0), (2, 0), (2, 1)],
[(0, 1), (1, 1), (2, 1)],
[(0, 1), (1, 0), (2, 0)],
[(1, 0), (2, 0), (2, -1)],
[(1, 0), (1, 1), (2, 1)],
[(0, 1), (1, 0), (-1, 1)],
[(0, 1), (1, 0), (1, -1)],
[(0, 1), (1, 1), (1, 2)],
[(0, 1), (0, 2), (1, 1)],
[(1, 0), (1, 1), (1, -1)],
[(1, 0), (2, 0), (1, -1)],
[(1, 0), (1, 1), (2, 0)]
]
answer = 0
for i in range(n):
for j in range(m):
for k in range(19):
temp = board[i][j]
for l in range(3):
try:
new_r = i + blocks[k][l][0]
new_c = j + blocks[k][l][1]
temp += board[new_r][new_c]
except IndexError:
continue
answer = max(answer, temp)
print(answer)