import sys input = sys.stdin.readline from collections import Counter H,W=map(int,input().split()) A=[list(map(int,input().split())) for i in range(H)] T=Counter() Y=Counter() P=Counter() M=Counter() for i in range(H): for j in range(W): T[i]+=A[i][j] Y[j]+=A[i][j] P[i+j]+=A[i][j] M[i-j]+=A[i][j] ANS=0 for i in T: for j in T: if i==j: continue ANS=max(ANS,T[i]+T[j]) for i in Y: for j in Y: if i==j: continue ANS=max(ANS,Y[i]+Y[j]) for i in P: for j in P: if i==j: continue ANS=max(ANS,P[i]+P[j]) for i in M: for j in M: if i==j: continue ANS=max(ANS,M[i]+M[j]) for i in T: for j in Y: ANS=max(ANS,T[i]+Y[j]-A[i][j]) for i in T: for j in P: # x=i # x+y=j y=j-i if 0<=y