size = list(map(int, input().split(" ")))

isOdd = size[0] % 2 == 1 or size[1] % 2 == 1 
suma = 0
nejmin = 1001
for x in range(size[0]):
    row = list(map(int, input().split(" ")))
    suma += sum(row)
    for y in range(len(row)):
        if x == 0 and y == size[1] - 2:
            continue
        if x == 1 and y == size[1] - 1 :
            continue
        if x == size[0] - 1  and y == 1:
            continue
        if x == size[0] - 2 and y == 0:
            continue
        nejmin = min(nejmin, row[y])

print(suma if isOdd else suma - nejmin)

