#include <iostream>
#include <vector>

using namespace std;

int izracunaj(vector< vector<long int> > a, int N, int M, int qX, int qY) {
	a[qX][qY] = 2000000000;
	
	for (int j=1; j<M; j++)
		a[0][j] += a[0][j-1];
		
	for (int i=1; i<N; i++)
		a[i][0] += a[i-1][0];
		
	for (int i=1; i<N; i++) {
		for (int j=1; j<M; j++) {
			if (a[i-1][j] < a[i][j-1])
				a[i][j] += a[i-1][j];
			else
				a[i][j] += a[i][j-1];
		}
	}
	
	return a[N-1][M-1];
}

int main() {
	vector< vector<long int> > a;
	
	int N, M;
	long int pom;
	
	cin >> N >> M;
	
	for (int i=0; i<N; i++) {
		vector<long int> red;
		for (int j=0; j<M; j++) {
			cin >> pom;
			red.push_back(pom);
		}
		a.push_back(red);
	}
	
	cout << izracunaj(a, N, M, 1, 3);
	
	return 0;
}