#include <bits/stdc++.h>

using namespace std;
int sum;
int main()
{
    int n , m;
    cin >> n >> m;
    vector<vector<int> > matrica(n);
    for(int i = 0; i < n; i++){
        matrica[i].resize(m);
        for(int j = 0; j < m; j++){
            cin >> matrica[i][j];
        }
    }
    vector<vector<int> > prefredovi(n);
    vector<vector<int> > prefkolone(n);
    for(int i = 0; i < n; i++){
        sum = matrica[i][0];
        prefredovi[i].resize(m);
        prefkolone[i].resize(m);
        prefredovi[i][0] = matrica[i][0];
        for(int j = 1; j < m; j++){
            prefredovi[i][j] =  2*matrica[i][j]+sum;
            sum += prefredovi[i][j];
        }
    }
    for(int j = 0; j < m; j++){
        sum = 2*matrica[0][j];
        prefkolone[0][j] = matrica[0][j];
        for(int i = 1; i < n; i++){
            prefkolone[i][j] = matrica[i][j] + sum;
            sum += prefkolone[i][j];
        }
    }
    /*for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cout << prefredovi[i][j] <<" ";
        }
        cout << "\n";
    }
    cout << "\n";
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cout << prefredovi[i][j] <<" ";
        }
        cout << "\n";
    }
    cout << "\n" ;*/
    vector<vector<int> > DP(n);
    for(int i = 0; i < n; i++){
        DP[i].resize(m);
        DP[i][0] = 0;
    }
    for(int j = 0; j < m; j++){
        DP[0][j] = 0;
    }
    for(int i = 1; i < n; i++){
        for(int j = 1; j < m; j++){
            DP[i][j] = min(DP[i-1][j] + prefredovi[i][j-1],DP[i][j-1] + prefkolone[i-1][j]);
        }
    }
    /*for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cout << DP[i][j] << " ";
        }
        cout << '\n';
    }*/
    cout << DP[n-1][m-1];
    return 0;
}