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) * 3 D = [[-1, 1], [0, 1], [1, 1], [1, -1], [1, 0], [1, 1]] ans = 0 for i in range(N - 1): HW = i // (H * 3) if HW == 0: x = i // 3 y = 0 else: y = (i - H * 3) // 3 x = 0 cnt1 = 0 P = set() dx, dy = D[3 * HW + i % 3] 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): HW = j // (H * 3) if HW == 0: x = j // 3 y = 0 else: y = (j - H * 3) // 3 x = 0 cnt2 = 0 dx, dy = D[3 * HW + j % 3] 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 ans = max(ans, cnt1 + cnt2) #print(i,j,cnt1,cnt2) print(ans)