#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    int m;
    cin >> n;
    cin >> m;
    vector<int> col(m,0);
    vector<int> row(n,0);
    vector<vector<int>> mat;
    for(int i =0;i < n;i++){
        vector<int> v(m,0);
        mat.push_back(v);
    }
    for(int i = 0;i < n;i++){
            int sum = 0;
        for(int j = 0;j < m;j++){
            int num;
            cin >> num;
            mat[i][j] = num;
            sum += num;
            col[j] += num;
        }
        row[i] = sum;
    }
    int curri = 0;
    int currj = 0;
    long long int sumRow = row[0] - mat[0][0];
    long long int sumCol = col[0] - mat[0][0];
    for(int i = 0;i < m;i++){
        col[i] -= mat[0][i];
    }
    for(int i = 0;i < n;i++){
        row[i] -= mat[i][0];
    }
    int total = 0;
    while(curri != n - 1 || currj != m - 1){
        if(curri == n - 1){
            currj++;
            total += sumCol;
            sumCol += col[currj];
            for(int i = 0;i < n;i++){
                row[i] -= mat[i][currj];
            }
            for(int i = 0 ; i <= curri;i++){
                sumRow -= mat[i][currj];
            }
        }
        else if(currj == m - 1){
                curri++;
                total += sumRow;
                sumRow += row[curri];
                for(int i = 0;i < m;i++){
                    col[i] -= mat[curri][i];
                }
                for(int i = 0 ; i <= currj;i++){
                    sumCol -= mat[curri][i];
                }
        }
        else{
            if(sumCol >= sumRow){
                curri++;
                total += sumRow;
                sumRow += row[curri];
                for(int i = 0;i < m;i++){
                    col[i] -= mat[curri][i];
                }
                for(int i = 0 ; i <= currj;i++){
                    sumCol -= mat[curri][i];
                }
            }
            else{
                currj++;
                total += sumCol;
                sumCol += col[currj];
                for(int i = 0;i < n;i++){
                    row[i] -= mat[i][currj];
                }
                for(int i = 0 ; i <= curri;i++){
                    sumRow -= mat[i][currj];
                }
            }
        }
    }
    cout << total;
    return 0;
}