#include <bits/stdc++.h>
using namespace std;

struct koordinate{int x, y;};

koordinate put[1000];

long long sol = LONG_MAX;

int m, n;
long long niz[10005][10005];


bool unutra(koordinate a, int duzina) {
    for(int i = 0; i < duzina; i++) {
        if(put[i].x == a.x && put[i].y == a.y) return true;
    }
    return false;
}


long long sracunaj(int duzina) {
    long long soll = 0;
    for(int i = 0; i < n; i++) {
        bool desno = false;
        for(int j = 0; j < m; j++) {
            koordinate znj = {j, i};
            if(unutra(znj, duzina)) {
                desno = true;
                continue;
            }
            int tmp = niz[znj.x][znj.y];
            if(!desno) {
                while(!unutra(znj, duzina)) {
                    soll += tmp;
                    znj.x++;
                }
            }
            else {
                while(!unutra(znj, duzina)) {
                    soll += tmp;
                    znj.y++;
                }
            }
        }
    }
    return soll;
}
bool check(koordinate a) {
    if(a.x >= m && a.y >= n) return false;
    return true;
}
void nadjiPut(koordinate a, int duzina) {
    if(!check(a)) return;
    put[duzina] = a;
    if(a.x == m - 1 && a.y == n - 1) {
        sol = min(sol, sracunaj(duzina + 1));
    }
    koordinate b;
    b.x = a.x + 1;
    b.y = a.y;
    if(!(b.x >= m))
        nadjiPut(b, duzina + 1);
    b.y++;
    b.x--;
    if(!(b.y >= n))
        nadjiPut(b, duzina + 1);
}

int main() {
    cin >> m >> n;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> niz[i][j];
    nadjiPut({0, 0}, 0);
    cout << sol << endl;
}