def func_odd(table) -> int:
    return sum([sum(x) for x in table])

def func_even(table, row: int, col: int) -> int:
    tmp = sum([sum(x) for x in table[:-2]])
    tmp += sum(table[-2][:-2])
    tmp += sum(table[-1][:-2])

    x = table[-2][-2] + table[-2][-1] + table[-1][-1]
    y = table[-2][-2] + table[-1][-2] + table[-1][-1]
    
    tmp += max(x, y)

    return tmp

def main():
    row, col = tuple(map(int, input().split()))

    table = []
    
    for i in range(row):
        table.append(list(map(int, input().split())))

    if row % 2 == 1 or col % 2 == 1:
        print(func_odd(table))
    else:
        print(func_even(table, row, col))

main()
