def hamster(stringg):
    print(stringg)
    countr=0
    total_num = 0
    s = stringg.split(" ")
    x = int(s[0])
    y = int(s[1])
    s = s[2:]
    lowest_val=1001
    for i in range(len(s)):
        a = s[i].split(" ")
        for j in range(len(a)):
            total_num+=int(a[j])
            if (not i==0 or not j==0 ) and (int(a[j])<lowest_val) and (not i==x-1 or not j==y-1) or countr==1:
                lowest_val=int(a[j])
            countr+=1
    if (x%2==0) and (y%2==0):
        total_num-=lowest_val
    return(str(total_num))

xandy=input().split(" ")
lines = []
inputstring = f"{xandy[0]} {xandy[1]}"
for i in range(int(xandy[0])):
    inputstring+= f" {(input())}"

print(hamster(inputstring))