import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Hamster {

    static int x, y, sum = 0, min = 1000;
    public static void main(String[] args) {
        readInput(args);

        if (isEven(x) && isEven(y)) {
            sum -= min;
        }

        System.out.println(sum);
    }

    private static boolean isEven(int a) {
        return a % 2 == 0;
    }

    private static void readInput(String[] args) {
        Scanner scanner = new Scanner(getSystemInputStream());
//        Scanner scanner = new Scanner(getStaticInputStream1());
//        Scanner scanner = new Scanner(getStaticInputStream2());
        x = scanner.nextInt();
        y = scanner.nextInt();
        scanner.nextLine();
        IntStream.range(0, x).forEach(ix -> {
            IntStream.range(0, y).forEach(iy -> {
                int value = scanner.nextInt();
                sum += value;
                Point p = new Point(ix, iy);
                if (
                        p.isAt(0,0)
                        || p.isAt(1,1)
                        || p.isAt(0, y-2)
                        || p.isAt(1, y-1)
                        || p.isAt(x - 2, 0)
                        || p.isAt(x - 1, 1)
                        || p.isAt(x - 2, y - 2)
                        || p.isAt(x - 1, y - 1)
                ) {
                    // skip
                }
                else {
                    min = Math.min(min, value);
                }
            });
        });
    }

    record Point(int x, int y) {
        public boolean isAt(int x, int y) {
            return this.x == x && this.y == y;
        }
    }
    private static InputStream getSystemInputStream() {
        return System.in;
    }

    private static InputStream getStaticInputStream1() {
        return new StringBufferInputStream(
                """
                    2 2
                    1 2
                    3 4
                    """);
    }

    private static InputStream getStaticInputStream2() {
        return new StringBufferInputStream(
                """
                    3 4
                    2 2 4 0
                    1 3 1 0
                    2 5 3 1
                    """);
    }
}
