#include <iostream>
#include <vector>

using namespace std;

int bektrek(int sum, int x, int y, vector<vector<int>> ravan) {

    if (x == 0 || y == 0) {
        return sum;
    }
    int newx = 0;
    int newy = 0;
    for (int i = 0; i < x; i++) {
        newx += ravan[i][y] * (x-i);
    }for (int i = 0; i < y; i++) {
        newy += ravan[x][i] * (y-i);
    }
    return min(bektrek(newy + sum, x-1, y, ravan), bektrek(newx + sum, x, y-1, ravan));


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,x;
    cin >> n >> m;
    vector<vector<int>> ravan;
    vector<int> temp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> x;
            temp.push_back(x);
        }
        ravan.push_back(temp);
    }

    cout << bektrek(0, n-1, m-1, ravan);

    return 0;
}