#include using namespace std; int main(){ long long rows, cols; cin >> rows >> cols; long long sum = 0; long long min = -1; for(long long i = 0; i < rows; i++){ for(long long j = 0; j < cols; j++){ long long 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; }