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,j in l: for ii,jj in l: for dx,dy in d: for ddx,ddy in d: se=set() if not(1<=i+dx<=h) or not(1<=j+dy<=w) or not(1<=ii+ddx<=h) or not(1<=jj+ddy<=w): continue nowi=i+dx nowj=j+dy tmp=0 cnt=0 while 1<=nowi<=h and 1<=nowj<=w: cnt+=1 tmp+=A[nowi-1][nowj-1] se.add(nowi*200+nowj) nowi+=dx nowj+=dy if cnt==0: continue nowi=ii+ddx nowj=jj+ddy while 1<=nowi<=h and 1<=nowj<=w: if nowi*200+nowj not in se: tmp+=A[nowi-1][nowj-1] se.add(nowi*200+nowj) nowi+=ddx nowj+=ddy ans=max(ans,tmp) print(ans)