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]],[[-1,-1],[-1,0],[-1,1]],[[-1,1],[0,1],[1,1]],[[-1,-1],[0,-1],[1,-1]]] s = set() for j in range(w+2): s.add((0,j,0)) s.add((h,j,1)) for j in range(h+2): s.add((j,0,2)) s.add((j,w,3)) for x,y,e in s: for dx,dy in dxy[e]: 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,o in s: if x == u and y == v: continue for dx,dy in dxy[o]: 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)