H, W = map(int, input().split()) A = [[0] * (W + 2)] A += [[0] + list(map(int, input().split())) + [0] for _ in range(H)] A += [[0] * (W + 2)] H += 2 W += 2 N = (H + W) * 9 * 2 D = [] for i in range(-1, 2): for j in range(-1, 2): D.append((i, j)) dic = {} for i, (x, y) in enumerate(D): dic[(-x, -y)] = i ans = 0 def HWC(x): if x < H * 9: return (x // 9, 0) x -= H * 9 if x < H * 9: return (x // 9, W - 1) x -= H * 9 if x < W * 9: return (0, x // 9) x -= W * 9 return (H - 1, x // 9) Q = set() for i in range(N - 1): if i in Q: continue x, y = HWC(i) cnt1 = 0 P = set() dx, dy = D[i % 9] x += dx y += dy while 0 <= x < H and 0 <= y < W and A[x][y] > 0: cnt1 += A[x][y] P.add((x, y)) x += dx y += dy for j in range(i + 1, N): x, y = HWC(j) cnt2 = 0 dx, dy = D[j % 9] x += dx y += dy while 0 <= x < H and 0 <= y < W and A[x][y] > 0: if (x, y) not in P: cnt2 += A[x][y] x += dx y += dy if y == W - 1: Q.add((H + y) * 9 + dic[(dx, dy)]) elif x == 0: Q.add((2 * H + x) * 9 + dic[(dx, dy)]) elif x == H - 1: Q.add((2 * H + W + x) * 9 + dic[(dx, dy)]) ans = max(ans, cnt1 + cnt2) # print(i, HWC(i), D[i % 9], j, HWC(j), D[j % 9], cnt1, cnt2) print(ans)