// Author: Louis Siu :)
// O(mn) time DP solution for the problem Little Stone Road, mini-contest
// For problem definition, please download the file
// http://i.cs.hku.hk/~provinci/note/TFT2006P1.zip
/*
  Input format:
  [# of rows] [# of columns]
  c(0,0) c(0,1) c(0,2) ... c(0,n-1)

  Output: the maximum score of any path from the top row to the bottom row
*/
#include <iostream>
using namespace std;

int r, c;              // # of rows and columns
int board[110][110];   // stores the integers on the board
// L[i][j] = the max. score of paths ending at square(i,j) coming from the left
// or above
int L[110][110];
int R[110][110];

int main(){

  while (cin >> r >> c){
    // read input
    for (int i = 0; i < r; ++i)
      for (int j = 0; j < c; ++j)
        cin >> board[i][j];
    // base cases (the top row)
    L[0][0] = board[0][0];
    for (int i = 1; i < c; ++i)
      L[0][i] = max(L[0][i-1] + board[0][i], board[0][i]);
    R[0][c-1] = board[0][c-1];
    for (int i = c-2; i >= 0; --i)
      R[0][i] = max(R[0][i+1] + board[0][i], board[0][i]);
    // fill the rest
    for (int i = 1; i < r; ++i){
      L[i][0] = R[i-1][0] + board[i][0];
      for (int j = 1; j < c; ++j)
        L[i][j] = max(L[i][j-1], max(L[i-1][j], R[i-1][j])) + board[i][j];
      R[i][c-1] = L[i-1][c-1] + board[i][c-1];
      for (int j = c-2; j >= 0; --j)
        R[i][j] = max(R[i][j+1], max(L[i-1][j], R[i-1][j])) + board[i][j];
    }
    // output the answer
    int ans = -99999999;
    for (int i = 0; i < c; ++i)
      ans = max(ans, max(L[r-1][i], R[r-1][i]));
    cout << ans << '\n';
  }
  
}
