#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>
#include <regex.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)<0?-(a):(a))
#define alloc(type,size) calloc(sizeof(type),size)



int main(void){
	int h,w;
	int **a;

	int i;
	int j;
	int **map;
	char **way;
	int res = 0;

	scanf("%d%d",&h,&w);
	a = alloc(int*,h+2);
	map = alloc(int*,h+2);
	way = alloc(char*,h+2);
	for(i=0;i<h+2;i++){
		a[i] = alloc(int,w+2);
		a[i]++;
		map[i] = alloc(int,w+2);
		map[i]++;
		way[i] = alloc(char,w+2);
		way[i]++;
	}
	a++;
	map++;
	way++;

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			map[i][j] = max(map[i-1][j],map[i][j-1]) + a[i][j];
			if(i>j) way[i][j] = map[i-1][j] > map[i][j-1] ? 'u' : 'l';
			else way[i][j] = map[i-1][j] >= map[i][j-1] ? 'u' : 'l';
		}
	}
	i = h-1;j = w-1;
	res = map[i][j];
	while(i || j){
		a[i][j] = 0;
		if(way[i][j] == 'u') i--;
		else j--;
	}
	a[i][j] = 0;

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			map[i][j] = max(map[i-1][j],map[i][j-1]) + a[i][j];
			if(i>j) way[i][j] = map[i-1][j] > map[i][j-1] ? 'u' : 'l';
			else way[i][j] = map[i-1][j] >= map[i][j-1] ? 'u' : 'l';
		}
	}
	i = h-1;j = w-1;
	res += map[i][j];

	printf("%d\n", res);
    return 0;
}
