#include <bits/stdc++.h>

using namespace std;
#define int long long

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

int r = INT_MAX;
int n, m;
void f(int x, int y, int tr){
    if(x != n-1){
        f(x+1, y, tr+pref[x+1][m]-pref[x+1][y+1]);
    }
    if(y != m-1){
        f(x, y+1, tr+pref[n][y+1]-pref[x+1][y+1]);
    }
    if(x == n-1){
        r = min(r, tr+pref[x][m]-pref[x][y+1]);
        return;
    }
    if(y == m-1){
        r = min(tr+pref[n][y]-pref[x+1][y],r);
        return;
    }
}
signed main()
{
    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 x = 0;
    int y = 0;

    f(0,0,0);

    cout << r << "\n";

    return 0;
}