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 for i1 in range(h+2): for j1 in range(w+2): for i2 in range(h+2): for j2 in range(w+2): if (1<=i1<=h and 1<=j1<=w) or (1<=i2<=h and 1<=j2<=w): continue 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)