#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, m, sums[1555][1555], a[1555][1555];
long long ans, dp[1555][1555], prevmax;
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++)
      if (j)
        sums[i][j] = sums[i][j - 1] + a[i][j];
      else
        sums[i][j] = a[i][j];
  for (int i = 0; i < (int)(n); i++) {
    ans = -1e18;
    if (i % 2 == 1) {
      prevmax = dp[i - 1][m - 1];
      for (int j = m - 2; j >= 0; j--) {
        dp[i][j] = sums[i][j] + prevmax;
        ans = max(ans, dp[i][j]);
        prevmax = max(prevmax, dp[i - 1][j]);
      }
    } else {
      if (i) {
        prevmax = dp[i - 1][0];
        for (int j = 1; j < m; j++) {
          dp[i][j] = sums[i][j] + prevmax;
          ans = max(ans, dp[i][j]);
          prevmax = max(prevmax, dp[i - 1][j]);
        }
      } else
        for (int j = 0; j < (int)(m); j++) dp[i][j] = sums[i][j];
    }
  }
  cout << ans;
  return 0;
}
