H,W=map(int,input().split()) A=[] A.append([0]*(H+2)) for i in range(H): A.append([0]+list(map(int,input().split()))+[0]) A.append([0]*(H+2)) starts=[] for i in range(H+1): for j in range(W+1): for dx in range(-1,2): for dy in range(-1,2): if i==H+1 or i==0 or j==0 or j==W+1: if 1<=i+dx<=H and 1<=j+dy<=W: starts.append([i,j,dx,dy]) pos_to_ans={} for i,j,dx,dy in starts: ans=0 i2,j2=i,j while 1<=i2+dx<=H and 1<=j2+dy<=W: i2+=dx j2+=dy ans+=A[i2][j2] pos_to_ans[(i,j,dx,dy)]=ans dic={} Set=set() for i in range(1,H): for j in range(1,W): last=[] for dx in range(-1,2): for dy in range(-1,2): if dx==dy==0: continue i2,j2=i,j while 1<=i2<=H and 1<=j2<=W: i2+=dx j2+=dy last.append((i2,j2,dx,dy)) for x1,y1,dx1,dy1 in last: for x2,y2,dx2,dy2 in last: dic[(x1,y1,dx1,dy1,x2,y2,dx2,dy2)]=A[i][j] print(dic) ans=0 for i,j,dx,dy in starts: for i2,j2,dx2,dy2 in starts: ans_d=pos_to_ans[(i,j,dx,dy)]+pos_to_ans[(i2,j2,dx2,dy2)] ge=dic.get((i,j,dx,dy,i2,j2,dx2,dy2)) if ge!=None: ans_d-=ge ans=max(ans,ans_d) print(ans)