#include using namespace std; int main(){ int rows, cols; cin >> rows >> cols; int sum = 0; int min = -1; for(int i = 0; i < rows; i++){ for(int j = 0; j < cols; j++){ int x; cin >> x; if(rows % 2 == 0 && cols % 2 == 0){ if(!((i == 0 && j == 0) || (i == rows-1 && j == cols-1))){ if(min == -1 || x < min) { min = x; } } } sum += x; } } if (min != -1) sum -= min; cout << sum << endl; }