h,w=map(int,input().split()) a=[[0]*(w+2)] for i in range(h): a+=[[0]+list(map(int,input().split()))+[0]] a+=[[0]*(w+2)] v=[[0]*(w+2) for i in range(h+2)] g=0 c=0 s=[] for i in range(h+2): for j in range(w+2): if 1<=i<=h and 1<=j<=w: continue s+=[(i,j)] for i1,j1 in s: for i2,j2 in s: for dx1 in [-1,0,1]: for dy1 in [-1,0,1]: for dx2 in [-1,0,1]: for dy2 in [-1,0,1]: if (dx1,dy1)==(0,0) or (dx2,dy2)==(0,0): continue c+=1 p=0 x1=i1 y1=j1 while 0<=x1+dx1<=h+1 and 0<=y1+dy1<=w+1: x1+=dx1 y1+=dy1 if v[x1][y1]!=c: v[x1][y1]=c p+=a[x1][y1] x2=i2 y2=j2 while 0<=x2+dx2<=h+1 and 0<=y2+dy2<=w+1: x2+=dx2 y2+=dy2 if v[x2][y2]!=c: v[x2][y2]=c p+=a[x2][y2] g=max(g,p) print(g)