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 i == H - 1 or j == 0 or j == W - 1: L.append((i, j)) dx = [1, 0, -1, 0, 1, 1, -1, -1] dy = [0, 1, 0, -1, 1, -1, 1, -1] def f(x1, y1, k1, x2, y2, k2): S = set() while True: S.add((x1, 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, 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 x1, y1 in L: for k1 in range(8): for x2, y2 in L: for k2 in range(8): S = f(x1, y1, k1, x2, y2, k2) temp = 0 for xs, ys in S: temp += A[xs][ys] ans = max(ans, temp) print(ans)