h,w=map(int,input().split()) a=[list(map(int,input().split())) for i in range(h)] if h<=2 or w<=2: g=0 for i in range(h): for j in range(w): g+=a[i][j] print(g) exit() g=0 for kaiten in range(4): for hanten in range(2): A=[[0]*(h-1+w+h-1) for i in range(h)] for i in range(h): for j in range(w): A[i][j+h-1]=a[i][j] b1=[[0]*(h-1+w+h-1) for i in range(h)] for i in range(h): b1[i][h-1+w-1+i]=sum(A[i]) for i in range(h): for j in reversed(range(i,i+h-1+w-1)): b1[i][j]=b1[i][j+1] b2=[[0]*(h-1+w+h-1) for i in range(h)] for j in range(h-1,h-1+w+h-1): b2[h-1][j]=sum(A[h-1-i][j-i] for i in range(h)) for i in reversed(range(h-1)): for j in range(i,i+w+h-1): b2[i][j]=b2[i+1][j+1] g=max(g,sum((sorted([b1[i][h-1+w-1+i] for i in range(h)]))[::-1][:2])) g=max(g,sum((sorted([b2[h-1][h-1+i] for i in range(h+w-1)]))[::-1][:2])) for i in range(h): for j in range(i,i+h-1+w): g=max(g,b1[i][j]+b2[i][j]-A[i][j]) na=[[0]*w for i in range(h)] for i in range(h): for j in range(w): na[i][~j]=a[i][j] a=na na=[[0]*h for i in range(w)] for i in range(h): for j in range(w): na[~j][i]=a[i][j] h,w=w,h a=na print(g)