import sys input = sys.stdin.readline h,w = map(int,input().split()) grid = [] for i in range(h): grid.append(list(map(int,input().split()))) ans = 0 dxy = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] s = set() for i in [0,h]: for j in range(w+2): s.add((i,j)) for i in [0,w]: for j in range(h+2): s.add((j,i)) for x,y in s: for dx,dy in dxy: temp = 1 cnt = 0 se = set() while 1 <= x+dx*temp <= h and 1 <= y+dy*temp <= w: cnt += grid[x+dx*temp-1][y+dy*temp-1] se.add((x+dx*temp-1,y+dy*temp-1)) temp += 1 if temp == 1: continue for u,v in s: if x == u and y == v: continue for dx,dy in dxy: c = 0 temp = 1 while 1 <= u+dx*temp <= h and 1 <= v+dy*temp <= w: if (u+dx*temp-1,v+dy*temp-1) in se: temp += 1 continue c += grid[u+dx*temp-1][v+dy*temp-1] temp += 1 ans = max(ans,cnt+c) print(ans)