import sys input = sys.stdin.readline h,w=map(int,input().split()) A=[list(map(int,input().split())) for _ in range(h)] d=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)] ans=0 l=[] for i in range(w+1): l.append((0,i)) for i in range(h+1): l.append((i,w+1)) for i in range(w+1): l.append((h+1,w+1-i)) for i in range(h+1): l.append((h+1-i,0)) for i,j in l: for ii,jj in l: for dx,dy in d: for ddx,ddy in d: se=set() nowi=i+dx nowj=j+dy tmp=0 while 1<=nowi<=h and 1<=nowj<=w: if (nowi,nowj) not in se: tmp+=A[nowi-1][nowj-1] se.add((nowi,nowj)) nowi+=dx nowj+=dy nowi=ii+ddx nowj=jj+ddy while 1<=nowi<=h and 1<=nowj<=w: if (nowi,nowj) not in se: tmp+=A[nowi-1][nowj-1] se.add((nowi,nowj)) nowi+=ddx nowj+=ddy ans=max(ans,tmp) print(ans)