H, W = map(int, input().split()) A = [] for i in range(H): A.append(list(map(int, input().split()))) L = [] for i in range(H): for j in range(W): if i == 0 or j == W - 1 or j == 0: L.append((i, j)) dx = [1, 0, 1, 1] dy = [0, 1, 1, -1] def f(x1, y1, k1, x2, y2, k2): S = set() while True: S.add(x1*W+y1) x1 += dx[k1] y1 += dy[k1] if x1 < 0 or x1 > H - 1 or y1 < 0 or y1 > W - 1: break while True: S.add(x2*W+y2) x2 += dx[k2] y2 += dy[k2] if x2 < 0 or x2 > H - 1 or y2 < 0 or y2 > W - 1: break return S ans = 0 for a in range(len(L)): x1, y1 = L[a] for k1 in range(4): if k1 == 0 and x1 != 0: continue if k1 == 1 and y1 != 0: continue if k1 == 2 and y1 == W - 1: continue if k1 == 3 and y1 == 0: continue for b in range(a, len(L)): x2, y2 = L[b] for k2 in range(4): if k2 == 0 and x2 != 0: continue if k2 == 1 and y2 != 0: continue if k2 == 2 and y2 == W - 1: continue if k2 == 3 and y2 == 0: continue S = f(x1, y1, k1, x2, y2, k2) temp = 0 for v in S: xs, ys = divmod(v, W) temp += A[xs][ys] ans = max(ans, temp) print(ans)