H,W=map(int,input().split()) A=[] B=[];C=[0]*W D,E={},{} for i in range(H): AA=list(map(int, input().split())) for j in range(W): C[j]+=AA[j] x=i+j if x not in D: D[x]=0 y=i-j if y not in E: E[y]=0 D[x]+=AA[j];E[y]+=AA[j] A.append(AA) B.append(sum(AA)) if H==1 and W==1: print(AA[0]) exit() DD,EE=[],[] for d in D: DD.append(D[d]) for e in E: EE.append(E[e]) BB=sorted(B)[::-1];CC=sorted(C)[::-1];DD=sorted(D)[::-1];EE=sorted(E)[::-1] ans=0 if len(BB)>1: ans=max(ans,BB[0]+BB[1]) if len(CC)>1: ans=max(ans,CC[0]+CC[1]) if len(DD)>1: ans=max(ans,DD[0]+DD[1]) if len(EE)>1: ans=max(ans,EE[0]+EE[1]) for h in range(H): for w in range(W): a=A[h][w] C=[B[h],C[w],D[h+w],E[h-w]] C=sorted(C)[::-1] ans=max(ans,C[0]+C[1]-a) print(ans)