def hamster(stringg):
    countr=0
    total_num = 0
    s = stringg.splitlines()
    x = int(s[0].split(" ")[0])
    y = int(s[0].split(" ")[1])
    s = s[1:]
    idk = ""
    for i in s:
        idk+= i+" .O. "
    print(f"x={x} y={y} s={idk}")
    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 = []
for i in range(xandy[0]):
    lines.append(input())

inputstring = f"{xandy[0]} {xandy[1]}"

for i in lines:
    inputstring=f'''{inputstring}
{lines[i]}'''

print(hamster(inputstring))