#include <bits/stdc++.h>

using namespace std;

vector< vector<int> > mat;
vector< vector<int> > pref;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;
    mat.resize(n+1);
    pref.resize(n+5);
    for(int i = 0; i <= n; i++){
        mat[i].resize(m);
        pref[i].resize(m+5);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> mat[i][j];
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            pref[i][j] = pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+mat[i-1][j-1];
        }
    }

    int r = 0;
    int x = 0;
    int y = 0;

    while(x != n-1 && y != m-1){
        if(mat[x+1][y] - (pref[x+1][m]-pref[x+1][y+1]) > mat[x][y+1]-(pref[n][y+1]-pref[x+1][y+1])){
           r += pref[x+1][m]-pref[x+1][y+1];
            x++;
        }
        else{
            r += pref[n][y+1]-pref[x+1][y+1];
            y++;
        }
    }
    if(x == n-1){
        r += pref[x][m]-pref[x][y+1];
    }
    else{
        r += pref[n][y]-pref[x+1][y];
    }
    cout << r << "\n";

    return 0;
}