#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
int n, m, in[1500][1500];
long long sum[2000][2000];
long long dp[2000][2000], dp2[2000][2000];
void run() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      scanf("%d", in[i] + j), dp[i][j] = dp2[i][j] = -(1LL << 60);
  for (int i = 0; i < n; i++) {
    sum[i][0] = in[i][0];
    for (int j = 1; j < m; j++) sum[i][j] = sum[i][j - 1] + in[i][j];
  }
  for (int j = 0; j < m; j++) dp[0][j] = sum[0][j];
  dp2[0][m - 1] = dp[0][m - 1];
  for (int j = m - 2; j >= 0; j--) dp2[0][j] = max(dp2[0][j + 1], dp[0][j]);
  for (int i = 1; i < n; i++) {
    if (i % 2 == 0) {
      for (int j = 1; j < m; j++)
        dp[i][j] = max(dp[i][j], dp2[i - 1][j - 1] + sum[i][j]);
      dp2[i][m - 1] = dp[i][m - 1];
      for (int j = m - 2; j >= 0; j--) dp2[i][j] = max(dp2[i][j + 1], dp[i][j]);
    } else {
      for (int j = 0; j < m - 1; j++)
        dp[i][j] = max(dp[i][j], dp2[i - 1][j + 1] + sum[i][j]);
      dp2[i][0] = dp[i][0];
      for (int j = 1; j < m - 1; j++) dp2[i][j] = max(dp2[i][j - 1], dp[i][j]);
    }
  }
  long long ans = -(1LL << 60);
  for (int j = 0; j < m; j++) ans = max(ans, dp[n - 1][j]);
  cout << ans << endl;
}
int main() { run(); }
