#include <bits/stdc++.h>
using namespace std;
int n, m;
long long t[1600][1600];
long long dp[1600][1600];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%lld", &t[i][j]);
      dp[i][j] = -1000000000000008LL;
    }
  }
  vector<vector<long long>> pf(n,
                               vector<long long>(m + 1, -1000000000000008LL));
  vector<vector<long long>> mxpf(n,
                                 vector<long long>(m + 1, -1000000000000008LL));
  vector<vector<long long>> mxsf(n,
                                 vector<long long>(m + 1, -1000000000000008LL));
  for (int i = 0; i < n; i++) {
    pf[i][0] = t[i][0];
    for (int j = 1; j < m; j++) {
      pf[i][j] = pf[i][j - 1] + t[i][j];
    }
  }
  mxpf[0][0] = pf[0][0];
  for (int j = 1; j < m; j++) mxpf[0][j] = max(mxpf[0][j - 1], pf[0][j]);
  for (int j = m - 1; j >= 0; j--) mxsf[0][j] = max(mxsf[0][j + 1], pf[0][j]);
  bool sm = true;
  for (int j = 0; j < m; j++) dp[0][j] = pf[0][j];
  for (int i = 1; i < n; i++) {
    if (sm) {
      for (int j = 0; j < m - 1; j++) {
        dp[i][j] = mxsf[i - 1][j + 1] + pf[i][j];
      }
      for (int j = m - 1; j >= 0; j--)
        mxsf[i][j] = max(mxsf[i][j + 1], dp[i][j]);
      mxpf[i][0] = dp[i][0];
      for (int j = 1; j < m; j++) mxpf[i][j] = max(dp[i][j], mxpf[i][j - 1]);
    } else {
      for (int j = 1; j < m; j++) {
        dp[i][j] = mxpf[i - 1][j - 1] + pf[i][j];
        mxpf[i][j] = max(dp[i][j], mxpf[i][j - 1]);
      }
      for (int j = m - 1; j >= 0; j--)
        mxsf[i][j] = max(mxsf[i][j + 1], dp[i][j]);
    }
    sm = !sm;
  }
  long long ans = -1000000000000008LL;
  for (int j = 0; j < m; j++) ans = max(dp[n - 1][j], ans);
  cout << ans;
  return 0;
}
