#include <bits/stdc++.h>
using namespace std;
int minimal=1000000000,n,m;

void rek(int i,int j,vector<vector<bool>> putanja,vector<vector<int>>& a){

    if (i+1<n){
        putanja[i+1][j]=true;
        rek(i+1,j,kopija,a);
        putanja[i+1][j]=false;
    }
    if (j+1<m){
        putanja[i][j+1]=true;
        rek(i,j+1,kopija,a);
        putanja[i][j+1]=false;
    }
    if ((i+1==n) and (j+1==m)){
        int rez=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){

                if (!putanja[i][j]){
                    bool dolekraj=false,desnokraj=false;
                    int desno=0,dole=0;
                    for (int k=j;k<m;k++){
                        if (putanja[i][k]){
                            desnokraj=true;
                            break;
                        }
                        desno++;
                    }

                    for (int k=i;k<n;k++){
                        if (putanja[k][j]){
                            dolekraj=true;
                            break;
                        }
                        dole++;
                    }
                    int min_put;
                    if ((dolekraj) and (desnokraj) and (desno>=dole)) min_put=dole;
                    else if ((dolekraj) and (desnokraj) and (dole>desno)) min_put=desno;
                    else if (dolekraj) min_put=dole;
                    else min_put=desno;
                    rez+=min_put*a[i][j];



                }


            }
        }

  /*      for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                cout<<putanja[i][j]<<" ";
            }
            cout<<endl;
        }

        cout<<rez<<endl<<endl;
    */    if (rez<minimal) minimal=rez;
        return;
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    vector<vector<int>> a(n,vector<int>(m));
    
    vector<vector<bool>> put(n,vector<bool>(m,false));
    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    put[0][0]=true;
    rek(0,0,put,a);
    cout<<minimal;

    return 0;
}