a, b = tuple([int(i) for i in input().split()])
x = []
for i in range(a):
    x.append([int(i) for i in input().split()])


def findLowestPossible():
    lowest = 1001
    for i in range(a):
        for j in range(b):
            if not((j, x) in [(0, 0), (b-1, a-1)] or j % 2 == i % 2):
                lowest = min(lowest, x[i][j])
    return lowest


s = sum(sum(x, []))
if a % 2 == 0 and b % 2 == 0:
    s -= findLowestPossible()
print(s)

'''axes = [(0, 1), (1, 0), (-1, 0), (0, -1)]
highest = 0
start = (0, 0)
finish = (b-1, a-1)
options = [[start, [start], x[start[1]][start[0]]]]

while options:
    newOptions = []
    for option in options:
        for axe in axes:
            p, q = option[0][0] + axe[0], option[0][1] + axe[1]
            if (p, q) == finish:
                highest = max(highest, option[2] + x[q][p])
            elif 0 <= p < b and 0 <= q < a and (p, q) not in option[1]:
                newOptions.append([(p, q), option[1].copy() + [(p, q)], option[2] + x[q][p]])
    options = newOptions.copy()
'''

