#include #include #include #define DEBUG true #define $(x) {if (DEBUG) {std::cout << "(line " << __LINE__ << ") "; {x} std::cout << std::endl;}} #define _(x) {std::cout << #x << " = " << x << " ";} int main() { int N, M; std::cin >> N >> M; // $(_(N)); // $(_(M)); std::vector> arr(N, std::vector(M, 0)); long sum = 0; long min = 1000; int tmp; for (int n = 0; n < N; n++) { for (int m = 0; m < M; m++) { std::cin >> tmp; sum += tmp; if ((n + m) % 2 == 1 && tmp < min) { min = tmp; } } } if (N % 2 == 0 && M % 2 == 0) { std::cout << (sum - min) << "\n"; } else { std::cout << sum << "\n"; } return 0; }