import sys input = sys.stdin.readline def read_values(): return tuple(map(int, input().split())) def read_list(): return list(read_values()) def main(): h,w=read_values() a=[] for _ in range(h): a.append(read_list()) ans=0 st=set() for i in range(-1,h+1): st.add((i,-1)) st.add((i,w)) for i in range(-1,w+1): st.add((-1,i)) d=[(0,1),(1,-1),(1,0),(1,1)] for fx,fy in st: for dx,dy in d: tmp=0 x=fx y=fy visit=set() while True: x+=dx y+=dy if x<0 or y<0 or x>=h or y>=w: break if not (x,y) in visit: tmp+=a[x][y] visit.add((x,y)) for fx2,fy2 in st: for dx2,dy2 in d: tmp2=tmp x=fx2 y=fy2 visit2=visit.copy() while True: x+=dx2 y+=dy2 if x<0 or y<0 or x>=h or y>=w: break if not (x,y) in visit2: tmp2+=a[x][y] visit2.add((x,y)) ans=max(ans,tmp2) print(ans) if __name__ == "__main__": main()