from sys import stdin
#mem=dict()
n,m=map(int,stdin.readline().split())
mem2=[[dict() for _ in range(m)] for _ in range(n)]
def dfs(x,y,l,r):
global mem2
b=[]
#if (x,y,l,r) in mem:
# return mem[(x,y,l,r)]
try:
if (l,r) in mem2[x][y]:
return mem2[x][y][(l,r)]
except:pass
if x!=n :
b.append(dfs(x+1,y+0,0 ,m-1)+a[x][y])
else:
#mem.update({(x,y,l,r):0})
try:
mem2[x][y].update({(l,r):0})
except:pass
return 0
if y<r:
b.append(dfs(x+0,y+1,y+1,r )+a[x][y])
if y>l:
b.append(dfs(x+0,y-1,l ,y-1)+a[x][y])
ans=max(b)
#mem.update({(x,y,l,r):ans})
mem2[x][y].update({(l,r):ans})
return ans
a=[list(map(int, stdin.readline().split())) for _ in range(n)]
for i in range(n+1):
#for j in range(m-1,-1,-1):
#print(n-i,j,j,m-1,"hi1") mem
# dfs(n-i,j,j,m-1)
dfs(n-i,m-1,0,m-1)
#for j in range(m):
#print(n-i,j,0,j,"hi2") mem
# dfs(n-i,j,0,j)
dfs(n-i,0,0,m-1)
#print(max([mem[(0,i,i,m-1)] for i in range(m)]
# +[mem[(0,i,0,i)] for i in range(m)]))
print(max([dfs(0,i,0,m-1) for i in range(m)]))