#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1515][1515];
long long ps[1515][1515];
long long dp[1515][1515];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]), dp[i][j] = INT_MIN;
  for (int i = 0; i < n; i++) {
    ps[i][0] = a[i][0];
    for (int j = 1; j < m; j++) ps[i][j] = ps[i][j - 1] + a[i][j];
  }
  vector<long long> pfm(m, -(1LL << 60));
  pfm[m - 1] = ps[0][m - 1];
  dp[0][m - 1] = ps[0][m - 1];
  for (int i = m - 2; i >= 0; i--) {
    dp[0][i] = ps[0][i];
    pfm[i] = max(pfm[i + 1], dp[0][i]);
  }
  for (int i = 1; i < n; i++) {
    if (i % 2 == 0) {
      for (int j = 1; j < m; j++) {
        dp[i][j] = ps[i][j] + pfm[j - 1];
      }
      pfm[m - 1] = dp[i][m - 1];
      for (int j = m - 2; j >= 0; j--) {
        pfm[j] = max(pfm[j + 1], dp[i][j]);
      }
    } else {
      for (int j = 0; j < m - 1; j++) {
        dp[i][j] = ps[i][j] + pfm[j + 1];
      }
      pfm[0] = dp[i][0];
      for (int j = 1; j < m; j++) {
        pfm[j] = max(pfm[j - 1], dp[i][j]);
      }
    }
  }
  long long ans = -(1LL << 60);
  for (int i = 0; i < m; i++) ans = max(ans, dp[n - 1][i]);
  cout << ans << endl;
}
