import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int N = 220;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt(), n = scanner.nextInt();
int[][] arr = new int[N][N];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = scanner.nextInt();
}
}
int[][] dp = new int[m][n];
Arrays.fill(dp[m - 1], 0xc0c0c0c0);
dp[m - 1][(n - 1) / 2 - 1] = arr[m - 1][(n - 1) / 2 - 1];
dp[m - 1][(n - 1) / 2] = arr[m - 1][(n - 1) / 2];
dp[m - 1][(n + 1) / 2] = arr[m - 1][(n + 1) / 2];
for (int i = m - 2; i >= 0; i--) {
for (int j = 0; j < n; j++) {
dp[i][j] = arr[i][j]
+ Math.max(dp[i + 1][Math.max(j - 1, 0)],
Math.max(dp[i + 1][j], dp[i + 1][Math.min(j + 1, n - 1)]));
}
}
System.out.println(Arrays.stream(dp[0]).max().getAsInt());
scanner.close();
}
}```