import sys input = sys.stdin.readline H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] ans = 0 for dx, dy in [(0, 1), (1, 0), (1, 1), (-1, 1)]: if dx==0: rng = range(1, H+1) elif dy==0: rng = range(1, W+1) else: rng = range(H+W+4) for x in rng: sco = 0 S = set() if dx==0: nx = x ny = 0 elif dy==0: nx = 0 ny = x elif dx==1: nx = x-(W+2) ny = 0 else: nx = x ny = 0 nx+=dx ny+=dy if dx==0 or dy==0: while 1<=nx<=H and 1<=ny<=W: sco += A[nx-1][ny-1] S.add((nx, ny)) nx+=dx ny+=dy else: while 1<=ny<=W: if 1<=nx<=H and 1<=ny<=W: sco += A[nx-1][ny-1] S.add((nx, ny)) nx+=dx ny+=dy for dx2, dy2 in [(0, 1), (1, 0), (1, 1), (-1, 1)]: if dx2==0: rng2 = range(1, H+1) elif dy2==0: rng2 = range(1, W+1) else: rng2 = range(H+W+4) for x2 in rng2: sco2 = 0 if dx2==0: nx2 = x2 ny2 = 0 elif dy2==0: nx2 = 0 ny2 = x2 elif dx2==1: nx2 = x2-(W+2) ny2 = 0 else: nx2 = x2 ny2 = 0 nx2+=dx2 ny2+=dy2 if dx2==0 or dy2==0: while 1<=nx2<=H and 1<=ny2<=W: if (nx2, ny2) not in S: sco2 += A[nx2-1][ny2-1] nx2+=dx2 ny2+=dy2 else: while 1<=ny2<=W: if 1<=nx2<=H and 1<=ny2<=W: if (nx2, ny2) not in S: sco2 += A[nx2-1][ny2-1] nx2+=dx2 ny2+=dy2 ans = max(ans, sco+sco2) print(ans)