import sys input = sys.stdin.readline def read_values(): return tuple(map(int, input().split())) def read_list(): return list(read_values()) def main(): h,w=read_values() a=[] for _ in range(h): a.append(read_list()) ans=0 sumH=[0]*(h+w) sumW=[0]*(h+w) sumHpW=[0]*(h+w) sumHmW=[0]*(h+w) for i in range(h): for j in range(w): sumH[i]+=a[i][j] sumW[j]+=a[i][j] sumHpW[i+j]+=a[i][j] sumHmW[i-j+w]+=a[i][j] s=set() for i in range(h): for j in range(w): ans=max(ans,sumH[i]+sumW[j]-a[i][j]) ans=max(ans,sumH[i]+sumHpW[i+j]-a[i][j]) ans=max(ans,sumH[i]+sumHmW[i-j+w]-a[i][j]) ans=max(ans,sumW[j]+sumHpW[i+j]-a[i][j]) ans=max(ans,sumW[j]+sumHmW[i-j+w]-a[i][j]) ans=max(ans,sumHpW[i+j]+sumHmW[i-j+w]-a[i][j]) s.add((0,i,1,j)) s.add((0,i,2,i+j)) s.add((0,i,3,i-j+w)) s.add((1,j,2,i+j)) s.add((1,j,3,i-j+w)) s.add((2,i+j,3,i-j+w)) for v in range(4): for i in range(h+w): for j in range(i+1,h+w): a1=[sumH[i],sumW[i],sumHpW[i],sumHmW[i]][v] a2=[sumH[j],sumW[j],sumHpW[j],sumHmW[j]][v] ans=max(ans,a1+a2) for v2 in range(v+1,4): for j in range(h+w): if (v,i,v2,j) in s: continue a1=[sumH[i],sumW[i],sumHpW[i],sumHmW[i]][v] a2=[sumH[j],sumW[j],sumHpW[j],sumHmW[j]][v2] ans=max(ans,a1+a2) print(ans) if __name__ == "__main__": main()