#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 10;
const int INF = 1e10 + 13;
long long arr[N][N];
long long dp[N][N], mx1[N][N], mx2[N][N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  for (int i = 0; i < n; i++) {
    long long sm = 0;
    for (int j = 0; j < m; j++) {
      sm += arr[i][j];
      dp[i][j] = sm;
      if (i > 0) {
        if (i % 2 == 1 && j < m - 1)
          dp[i][j] += mx2[i - 1][j + 1];
        else if (i % 2 == 0 && j > 0)
          dp[i][j] += mx1[i - 1][j - 1];
        else
          dp[i][j] = -INF;
      }
      mx1[i][j] = j ? max(mx1[i][j - 1], dp[i][j]) : dp[i][j];
    }
    mx2[i][m - 1] = dp[i][m - 1];
    for (int j = m - 2; j >= 0; j--) mx2[i][j] = max(mx2[i][j + 1], dp[i][j]);
  }
  cout << mx1[n - 1][m - 1] << endl;
  return 0;
}
