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][:-1])
    tmp += sum(table[-1][1:-2]) + table[-1][-1]

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

    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()
