#include <bits/stdc++.h>
using namespace std;
const int N = 1507;
const long long LINF = 1e15 + 7;
int n, m;
long long s[N][N], dp[N][N], pre[N][N], suf[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i < (n + 1); ++i) {
    for (int j = (1); j < (m + 1); ++j) {
      int x;
      scanf("%d", &x);
      s[i][j] = s[i][j - 1] + x;
    }
  }
  for (int i = (0); i < (N); ++i)
    for (int j = (0); j < (N); ++j) dp[i][j] = pre[i][j] = suf[i][j] = -LINF;
  for (int i = (1); i < (m + 1); ++i) dp[1][i] = s[1][i];
  for (int i = (1); i < (m + 1); ++i) pre[1][i] = max(pre[1][i - 1], dp[1][i]);
  for (int i = m; i > 0; --i) suf[1][i] = max(suf[1][i + 1], dp[1][i]);
  for (int i = (2); i < (n + 1); ++i) {
    if (i & 1) {
      for (int j = (1); j < (m + 1); ++j)
        dp[i][j] = max(dp[i][j], pre[i - 1][j - 1] + s[i][j]);
    } else {
      for (int j = (1); j < (m + 1); ++j)
        dp[i][j] = max(dp[i][j], suf[i - 1][j + 1] + s[i][j]);
    }
    for (int j = (1); j < (m + 1); ++j)
      pre[i][j] = max(pre[i][j - 1], dp[i][j]);
    for (int j = m; j > 0; --j) suf[i][j] = max(suf[i][j + 1], dp[i][j]);
  }
  long long ans = -LINF;
  for (int i = (1); i < (m + 1); ++i) ans = max(ans, dp[n][i]);
  printf("%lld", ans);
  return 0;
}
