import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 31) # inf = -1-(-1 << 63) # md = 10**9+7 md = 998244353 memo = {} ijs = {} def line(si, sj, di, dj): if (si, sj, di, dj) in memo: return memo[si, sj, di, dj] res = 0 i, j = si, sj st = set() while 0 <= i < h and 0 <= j < w: st.add((i, j)) res += aa[i][j] i, j = i+di, j+dj memo[si, sj, di, dj] = res ijs[si, sj, di, dj] = st return res def cross(i, j, di, dj, p, q, dp, dq): s=ijs[i, j, di, dj] t=ijs[p, q, dp, dq] if len(s)>len(t):s,t=t,s for a in s: if a in t:return a return -1,-1 def start(): for i in range(h): yield i, 0, 0, 1 yield i, 0, -1, 1 yield i, 0, 1, 1 for j in range(w): yield 0, j, 1, 0 yield 0, j, 1, 1 yield h-1, j, -1, 1 h, w = LI() aa = LLI(h) ans = 0 for i, j, di, dj in start(): for p, q, dp, dq in start(): if (i, j, di, dj) == (p, q, dp, dq): continue cur = line(i, j, di, dj)+line(p, q, dp, dq) ci, cj = cross(i, j, di, dj, p, q, dp, dq) if ci != -1: cur -= aa[ci][cj] if cur > ans: ans = cur # print(ans, i, j, di, dj, p, q, dp, dq) print(ans)